+ 1

I have a request.

Dear Programmers, Can somebody give me some code to build a simple calculator. Don't forget to specify what language the code is written in. Make sure it is either C++, C#, PHP, Java, Python, Ruby, or HTML and JavaScript. Please keep it simple! (•ᴥ•) Thanks, Carmelo the Awesome Programmer.

13th Dec 2016, 4:47 PM
Carmelo the Superb Programmer. ( ͡° ͜ʖ ͡°)
3 Respostas
+ 5
A simple calculator in C++. #include <iostream> #include <math.h> using namespace std; int main() { int a,b; char x; cin>>a>>x>>b; switch (x) { case '+': cout<<a+b; break; case '-': cout<<a-b; break; case '*': cout<<a*b; break; case '/': cout<<a/b; break; case '%': cout<<a%b; break; case '^': cout<<pow (a,b); break; case '~': cout<<sqrt (a); break; default: cout<<"Error"; } return 0; }
2nd Jan 2017, 12:22 AM
Bodan Talev
Bodan Talev - avatar
+ 4
Google exists, they will show you the code and explain it to you step by step. A calculator code is quite long to be honest, plus you will need to use a window application form instead of console.
13th Dec 2016, 5:12 PM
Wen Qin
Wen Qin - avatar
+ 1
/*This is a simple calculator for +,-,/,* and sin operations in python No GUI for the calculator */import math def add(): first=int(input("enter first number")) second=int(input("enter second number")) print(first+second) def subtract(): first=int(input("enter first number")) second=int(input("enter second number")) print(first-second) def multiple(): first=int(input("enter first number")) second=int(input("enter second number")) print(first*second) def divide(): first=int(input("enter first number")) second=int(input("enter second number")) print(first/second) def sin(): number=int(input("enter any number")) print(math.sin(number)) def cal_run(): op = input('enter + - * /') if op=='+': add() elif op=='-': subtract() elif op=='/': divide() elif op=='*': multiple() elif op=='s': sin() else: print("you entered a wrong operand") cal_run() cal_run()
14th Dec 2016, 6:26 AM
Agaba Ivan
Agaba Ivan - avatar