# Basic calculator in GO language

Hi I am new into the GO programming language.

I was struckeling with the following task;

I was creating a calculator that must be able to perform addition, subtraction, multiplication and division of two given integers.

• ``````  At the start of the program  it should  ask the user to select a operation like:

Select operation

2) Subtract

3) Multiply

4) Divide
``````
• ``````The user should enter there choice.       > ( Enter choice of operation (1/2/3/4):
``````
• ``````Ask user to enter the first interger                   > (enter first integer)
``````
• ``````Ask user to enter the second interger             > (enter second integer)
``````

Based on the operation selection of the user it should calculate the value of the two given integers.

Guillaume.

Hello !

You can create a function for every operation. Afterwards, in `main()` read the user input and call the appropriate function.

User input can consist of selection of operation and the number which operation will be applied.

Good luck

https://www.golang-book.com/books/intro

``````func add(int number1, int number2) int{

return number1 + number2;
}

func multiply(int number1, int number2) int{

return number1 * number2;
}

func divide(int number1, int number2) float{

if number2 ==  0 {
panic("you can not divide to 0") //or replace panic with fmt.Println();
}

return number1 / number2;
}

func substract(int number1, int number2) int{

return number1 - number2;
}
``````

This are the functions for the calculator. Hope it will help you.

Note that I am still learning Go If you spot a mistake, please let me know

Have a nice day 2 Likes