Ok, so I am making a basic number calculator using if statements and I have most of it done, and correctly. I just can't figure out how to add two things: For example if the user inputs an operator that is incorrect or unavailable it will output "error: no such operator" and if the user enters a problem that cannot be answered such as 200/0 then it will output "error: attempted division by zero".
Also, what should I use besides system ("PAUSE") to have the same effect without the security problems?
Here is the code I have so far, any help is much appreciated.
Thank you guys for the help so far. I have gotten the error message part down for the operator but I am trying to do the error message for "error: you cannot divide by zero" and when I run what I have and try to divide a number by zero the program freezes and I am forced to close it.
That's because you're doing the calculation before you check whether you have valid inputs for it. If num2 is 0, then line 3 will cause undefined behaviour, and if your program crashes there, then it will never get to the check on line 6.
There's no point checking your input after you've already performed the calculation. You need to rearrange the code so that:
1) You check for valid input before you actually attempt the calculation
2) You only perform the calculation if the inputs are valid