+ 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.
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;
}
+ 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.
+ 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()