whats up fellas. another assignment that is due somewhat soon that i have some questions on. the assignment description is:
Write a simple calculator program. Ask the user if s/he wants to add ('+') subtract ('-'), multiply ('*') or divide ('/') and then ask for the number. Perform the operation with the given number. Start the "display" at zero. Stop when the user enters 'X' (for exit). Use Do.. While and if statements.
.... so far i have this:
the output is coming out somewhat nice, but i am trying to figure out how to incorporate the operation into the output of the numbers. (ie: if user enters +, and then enters the number 20, the total displayed would be 20. but, after that, i am not sure how the next operation the user enters can effect the previously entered number.Code:#include <iostream> using namespace std; int main() { double n; char operation; cout << "Current Total is 0" << endl; do { cout << "Enter an operation: + - * / (or enter X to exit):"; cin >> operation; cout << "Enter a number: "; cin >> n; cout << "Current total is " << n << endl; } while (operation != 'X'); }
trying to explain this differently, using the same example, if the user entered +, then entered 20. the number displayed is 20. then, if the user entered the * operation next, and entered 2 for the next number, the 'new' current total should be 40. this is the part i am not sure how to do.
if any of you guys know how to help me with this, it would be awesome. and if you would like me to try to explain it a little better, i will do so as well.
again, thanks for any help guys.