Hi guys so i was creating a calculator for fun and i want to include a feature where you can just type 'q' to go back to "main menu", type another operation like subtract or divide to use that operation, and im stuck on this thing...
I know to use switch statement to make it easier but if you have a statement like
case 'q':
//go back to main
break;
case '//an operations like - or *'
//go to - or *
break;
...
but then how do i still get the numbers they want to add from the user? i don't think you can do that or can you?
1 2 3 4 5 6 7 8 9 10 11
switch (//the user input){
case'q' :
//here is the quit option;
break;
case -:
//here is the subtract option ;
break;
case number???:
//this is the part im stuck how can i still get a user number so i can add it with a previous number they inputted???
}
Like i tried putting another code outside the switch statement to add the previous user inputted number but it just did a random number like if 3 is the preivous input then i tried to add another input like 7 it gave me 58... what the heck???
string userInput = ... // get the input from the user
userInput = stripWhiteSpaces(userInput) // find a way to do this, must remove all spaces
if userInput[0] is oporator
doOperator(userInput[0])
elseif userInput[0] is number
doNumber(userInput)
else
print "Invalid input"
Now this pseudocode is oversimplified, but the idea is to make separate functions deal with operators and with numbers.