I am making a collection of math functions. I used if statements to create error messages and cut down on user errors.. I don’t think I did it right.
string error_0;
string error_i;
if (num1 == 0;) {error_0 = "You cannot divide by zero. Fail."}
else {error_0 = "";}
if (num1=<0;) {error_i = "Sorry, can't do imaginary numbers."} //for sqroot function
else {error_i = "";}
if (num2=<0;) {error_i = "Sorry, can't do imaginary numbers."}
else {error_i = "";}
… this gives me the following error messages in code::blocks compiling.
- expected “)” before “;” token (the if lines)
- expected primary expression before “)” token (the if lines)
- else without a previous if (just for the last else)
I’m really new at C++ and from the examples I have everything looks correct. Help would be appreciated. Thanks.
You need a semicolon after your strings and don’t need one inside the
ifconditions.Also, the operator is
<=, not=<.