-
May 10th, 2009, 05:20 PM
#1
do-if-else
Hello, I want to do a do-if-else and include a character.
Code:
do
{
cout << "\nWhat grade you think you will earn in this class? ";
cin >> final;
if (final == "A")
{
cout << "\nYou will get an A? ";
cout << "\nYou worked hard. ";
}
else
{
cout << "\nMaybe you should have studied more often!. ";
cout << "\nDon't be sad. ";
}
}
while;
pause();
}
It's char final. But it dosen't work. Also gives me an error for pause.
-
May 10th, 2009, 07:25 PM
#2
Re: do-if-else
How did you declare the final variable? If you declare it as std::string, then the comparison will work.
As for your other problem, your do-while statement is not right. In all while statement, you need to specify the condition to determine if the loop should still continue or end.
Code:
std::string final; // Declaring final as a string
do
{
cout << "\nWhat grade you think you will earn in this class? ";
cin >> final;
if (final == "A")
{
cout << "\nYou will get an A? ";
cout << "\nYou worked hard. ";
}
else
{
cout << "\nMaybe you should have studied more often!. ";
cout << "\nDon't be sad. ";
}
}
while(condition);
quoted from C++ Coding Standards:
KISS (Keep It Simple Software):
Correct is better than fast. Simple is better than complex. Clear is better than cute. Safe is better than insecure.
Avoid magic number:
Programming isn't magic, so don't incant it.
-
May 10th, 2009, 09:21 PM
#3
Re: do-if-else
Did you mean system("pause")?
-
May 10th, 2009, 10:26 PM
#4
Re: do-if-else
The syntax is
do
{
}
while (expression);
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|