if(x<0) x= -x;
Semantics
if(A) B else CA is evaluated and if true then B is executed but if A was false then C is executed.
if(A) BA is evaluated and if true B is executed otherwise nothing is done.
Most "if"s and "else"s have braces after them.
cin >> a;
cout << sqrt(a);
if(cin.fail()) cout << "input error";
Instead, something like this is more likely to work.
cin >> a;
if(cin.fail()) cout << "input error";
else cout << sqrt(a);
What is the syntax of an if-else statement?
What is the syntax of an if statement with no else?
What is the syntax of a block?
if(A) B else C
if(D) E else F
. . . . . . . . . ( end of section Quiz 2 next time on sequences of assignments) <<Contents | End>>