top of page
Search
Writer's picturelinuxtech

How to make a simple calculator using go language-


package main
import "fmt"  
  
func main() {  
 var operator string  
 var number1, number2 int  
 fmt.Print("Please enter First number: ")  
 fmt.Scanln(&number1)  
 fmt.Print("Please enter Second number: ")  
 fmt.Scanln(&number2)  
 fmt.Print("Please enter Operator (+,-,/,%,*):")  
 fmt.Scanln(&operator)  
 output := 0  
 switch operator {  
 case "+":  
  output = number1 + number2  
  break  
 case "-":  
  output = number1 - number2  
 case "*":  
  output = number1 * number2  
 case "/":  
  output = number1 / number2  
 case "%":  
  output = number1 % number2  
 default:  
  fmt.Println("Invalid Operation")  
 }  
 fmt.Printf("%d %s %d = %d", number1, operator, number2, output)  
}  


31 views0 comments

Recent Posts

See All

HOw to make a simple login form using HTML.

source code: <html> <head> <title>Login Page</title> </head> <body> <form name="loginForm" method="post" action="login.php"> <table...

How to make a simple snake game using html

source code: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width,...

Kommentare


bottom of page