QUOTE(aznballerlee @ 14 Oct, 2006 - 05:03 PM)

I don't understand what you mean by one line - no braces.
Azn,
C/C++ allows you to do the following with an
if statement:
CODE
if ( condition )
cout << "Condition evaluated to true";
else
cout << "condition evaluated to false";
which has
one line after the
if, and
doesn't require the
{}. which is the reason for saying "one line - no braces"
Optionally, you could have written:
CODE
if ( condition )
{
cout << "Condition evaluated to true";
}
else
{
cout << "condition evaluated to false";
}
They both do the same thing,
but had you done this:
CODE
if ( condition )
cout << "Condition evaluated to true" << endl;
cout << "Well done!";
else
cout << "condition evaluated to false";
Where you wanted
"Condition evaluated to true" and
"Well done!" to be displayed, then the use of the braces
{} is mandatory. It must be written as:
CODE
if ( condition )
{
cout << "Condition evaluated to true" << endl;
cout << "Well done!";
}
else
cout << "condition evaluated to false";
for the desired outcome and to successfully compile the program.
To save yourself some problems, use the braces in your if statements.
This post has been edited by gregoryH: 14 Oct, 2006 - 04:21 PM