You could create a simple menu that asks for user input to decide what operation they would like to use. That way the user can choose to type "End" or some other form.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
int choice = 0;
cout << " [1] Addition " << endl;
cout << " [2] Subtraction " << endl;
//Add other choices here
cout << "Enter 99999 to exit";
cout << "What would you like to do?" << endl;
cin >> choice;
do
{
//perform operations here
} (while choice != 99999)
I have a ton of variables that the user inputs so I don't want to write this:
Why are there lots of variables? If there are lots then the design is probably wrong. The psuedo code for a calculator is this:
1 2 3 4 5
//show the menu - a function
//get a number & validate it- a function
//get an operator & validate it- a function
//get a number - call this function again
//calc & print out the answer a function
You can make use of a while loop with a switch inside:
You could create a simple menu that asks for user input to decide what operation they would like to use. That way the user can choose to type "End" or some other form.
I did a very similar thing.
1 2 3
cout << endl << "Basic math = bm, Geometry = g, Square root = s. Power = p.";
However, lets say you are doing addition
Enter a number: 4
What do you want to add to 4? *Screw this.*
I want the user to be able to type end, and stop the program.
@TheIdeasMan
Its not just addition, its calculating area of shapes, subtraction, multiplication and division.
I could type out the 13 variables, but I want to know if there is a more effective way.
Its not just addition, its calculating area of shapes, subtraction, multiplication and division.
I could type out the 13 variables, but I want to know if there is a more effective way.
That doesn't matter, you can still put them in a switch - you can have as many operator as you like. IMO the switch is the best way.