-
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.
-
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);
-
Re: do-if-else
Did you mean system("pause")?
-
Re: do-if-else
The syntax is
do
{
}
while (expression);