| osamatanvir1 (1) | |||
I'm trying to make a calculator in which user can use it until a wrong key is given by user. After result when i press y to start the process again it start showing all the code in cmd and keeps continue. please help me how to stop the process so i can give values again.
| |||
|
|
|||
| softwaretime (24) | |||
Well first, you haven't declared a variable called "c", so create char c; so the option system works. The other thing to do is to make the calculation part into a function, which would look like this:
Base your program on the one above and it should bring the user back to the calc function every time they enter y. | |||
|
Last edited on
|
|||
| maeriden (341) | |
|
http://www.cplusplus.com/forum/general/89535/ why making a second topic about the same thing? Anyway, if you use a char to read the input for the operation to perform, its value will be equal to the ASCII code of the numberhttp://www.cplusplus.com/doc/ascii/ shows that '1' == 0x31 == 49 So to check the input you must do if(c == '1') or if(c == 49). The first one is preferred for readabilityHowever if c is an int, its value will be the actual number the user entersIf you use the approach softwaretime suggested, remember to declare y inside main
| |
|
|
|
| johnyxc (4) | |
| Just modify 'if(y)' to 'if(y == 'Y')' | |
|
|
|