I'm writing a calculator that can store the answer to memory and recall it later. I'm accomplishing this by allowing the user to store the answer when they choose whether or not to go again. I'm having the user type 's' to store the answer to memory. I want them to be able to type in '1 + s' and the program recognize s is the stored number. Any help to make this work correctly would be awesome. Thank you in advance.
but when I try to run it like this, the program stores the number correctly but then when I try to use it in an equation the program gets stuck in an infinite loop
The problem is that num1 and num2 are of type int, so they cannot contain 's'.
So, when you try to read with cin, and it encounters an 's', it cannot read it, and the read fails (num1 and num2 are probably left unchanged in case of fail). Then the program wil try to read 's' again in the 'default' case, but it fails to read it again for the same reason, and then you have programmed it to keep trying again and again, but it can never read an 's' into a variable of type 'int'.
So, you have to add two new variables: num1str and num2str of type string. Read the data with cin into those variables. Then, you can check whether they contain a number or an 's'. If they contain a number, convert the string to int with