

The final result is printed on the console screen using the built-in function fmt.Println().This function is defined under the fmt package and it helps to write standard output. Here we will use user input function – fmt.Scanln(), and then we call the function calculator() to calculate the result Next we start the function main().GO program execution starts with the function main(). Variable result is the final result integer variable.Ĭreate the switch case statement to execute the code with the input choice We imported the fmt package that includes the files of package fmtĬreate the function calculator() to calculate the choiceĭeclare and initialize the variables num1 and num2.

In the above program, we first declare the package main.
#C console calculator how to#
How to make a simple calculator using switch case in Syntax switch expression Įnter the following operation you want to perform If no case (choice entered) matches, it is a default case and its statements are executed. The cases are evaluated in an order and it stops when a case succeeds. The switch statement will assess an expression, comparing the expression's value against a series of case conditions given in a series and executes the statement after the first condition with a matching value, until a break is encountered.Ī switch statement runs the first case equal to the choice entered. In this tutorial we will see how to make a simple calculator using switch case statements in Go programming language.
