C++ If and if else error messages -
i making collection of math functions. used if statements create error messages , cut down on user errors.. don't think did right.
string error_0; string error_i; if (num1 == 0;) {error_0 = "you cannot divide zero. fail."} else {error_0 = "";} if (num1=<0;) {error_i = "sorry, can't imaginary numbers."} //for sqroot function else {error_i = "";} if (num2=<0;) {error_i = "sorry, can't imaginary numbers."} else {error_i = "";}
... gives me following error messages in code::blocks compiling.
- expected ")" before ";" token (the if lines)
- expected primary expression before ")" token (the if lines)
- else without previous if (just last else)
i'm new @ c++ , examples have looks correct. appreciated. thanks.
you need semicolon after strings , don't need 1 inside if
conditions. also, operator <=
, not =<
.
string error_0; string error_i; if (num1 == 0) {error_0 = "you cannot divide zero. fail.";} else {error_0 = "";} if (num1 <= 0) {error_i = "sorry, can't imaginary numbers.";} //for sqroot function else {error_i = "";} if (num2 <= 0) {error_i = "sorry, can't imaginary numbers.";} else {error_i = "";}
Comments
Post a Comment