Programming a calculator? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Programming a calculator?

so I'm new to coding I have a few rudiments under my belt but coding a calculator illudes me

17th Jan 2017, 12:08 AM
Micaiah Flores
Micaiah Flores - avatar
3 Answers
+ 9
Check out my simple calculator if you want to look for some example. And I will help you if you need any help and if you get stuck
17th Jan 2017, 7:29 AM
Filip
Filip - avatar
+ 1
check this out: #include <iostream> using namespace std; int main() { int a,b; char symb; cin >> a; cout << "first number:"<< a << endl; cin >> symb; cout << "symbol:" << symb << endl; cin >> b; cout << "second number:"<< b << endl; switch (symb) { case '+': cout << "sum:" << a+b << endl; break ; case '-': cout << "diff:" << a-b << endl; break; case '*': cout << "incr:" << a*b << endl; break; case '/': cout << "div:" << a/b << endl; break; } return 0; }
22nd Jan 2017, 8:54 PM
Vitalii Kovalskyi
Vitalii Kovalskyi - avatar
0
Try a command driven calculator for start. Use endless loop, inside on the beginning use cin to read a command to string. Then you can use if else if block to identify the command. Inside each if block do the operation. Like cin x cin y z=x*y cout z. If you want to evaluate a longer sequence from string, then you might want to create a simple parser with precedence, but that might be a bit difficult for start.
17th Jan 2017, 1:17 AM
John