Archived

This topic is now archived and is closed to further replies.

StoNeD_TrOLL

Problem with if

Recommended Posts

StoNeD_TrOLL    122
Okay,I am having a problem ending this if statement.My complier puts whatever is after my if statement in the statement.Heres the code: if (ank == 7) std::cout<<"_X_|___|___\n"; std::cout<<"___|___|___\n"; std::cout<<"___|___|___\n"; std::cout<<" | |\n"; so how do i end it?

Share this post


Link to post
Share on other sites
Martee    476
Enclose everything inside the if statement in braces {}. So ...
if (ank == 7)
{
std::cout << "blah\n";
...
...
}
std::cout << "We are no longer in the if statement\n";

Share this post


Link to post
Share on other sites
Krysole    140
Remember that cout, cin, fstream, ofstream, ... are all subclasses of iostream/iobase (or something like that anyway). so most funcs can be used accross the board and will achive similar results.

this is foolproof and if it doesn't work check your compiler settings (i'll be assuming that you're in std namespace 'using namespace std;' for simplicity):

if (ank == 7) {
cout << "_X_|___|___\n";
cout << "___|___|___\n";
cout << "___|___|___\n";
cout << " | |\n";
}
or you could take a small shortcut:

if (ank == 7) {
cout << "_X_|___|___\n"
<< "___|___|___\n"
<< "___|___|___\n"
<< " | |"
<< endl;
}

Edited by - Krysole on February 2, 2002 11:27:20 PM

Share this post


Link to post
Share on other sites