I've made a basic calculator, and I'd like to improve it. One of the ways doing this is by making the calculator capable of doing more operations at once.
Right now it can only do 1+1 =, 2-4= etc... So only with 2 numbers.
So I have 2 questions:
- how could I make it capable of doing operations like 3+4+2 (so with more then 2 numbers), and maybe even mixed operations (like 3+4-2).
- could I make an ans function, so it'd be able to keep on running, using the previous awnser.
A part of my code is this:
1 2 3 4 5 6 7 8 9 10 11 12 13
case 1:
cout << "****** Time to do some basic math!******" << endl;
cout << "____________Addition____________________" << endl;
cout << endl;
cout << "Enter number 1: ";
cin >> num1;
cout<<"\nEnter number 2: ";
cin >> num2;
result = num1 + num2;
cout<<num1<<" + "<<num2<<" = "<<result<<endl;
cout<<"The rounded result = "<<setprecision(3)<<result<<endl;
break;
And if you're awnsering, could you please explain why it should be done that way? I'm quite noob =)
This uses the variable you already have in a loop that executes as long as the user inputs a '+' sign for num1. There are probably a few things wrong with it but this was just to give you a general idea.
Enter something for num1 that isn't the '+' character. Like I said there are probably a few things wrong with this but it was a demonstration not a litereal "Here copy and paste this".