hi, I am trying to write some code to create a basic calculator. That is it will read a number, read an operator, read another number, then do the operation. The calculator works with integers and uses four functions: +, -, *, and /. After the first operation is completed, the program will read another operator and uses the result of the previous operation as the first value for the next operation. If the user enters a C the result is cleared and then the user starts entering a new number. If the user enters an X, the calculator is turned off. I haven't gotten to the clearing part yet or how to get the calculator to loop the calculation with the solution for the last calculation to act as the first for the next calculation. I am having troubles getting the program to terminate at the user input x.
Your problem is that you're asking cin to parse an integer value from the input. If the user enters 'X', it isn't parsed at all by cin and just left on the stream. If you want your feature to work, you will have to parse the input as a string and then later convert it to an integer if X is not detected.
Actually, another problem is that you have a semicolon on the end of line 28. That specifies an empty loop, and you'll just be there for infinite time if your while conditions are met.
looks like booradley is right; so here is something that is not good but it is workable.
I believe that one of your real problems is line 28 (that semicolon is causing you problems)
Try running your compiler with both -Wall and -Wextra