#include <iostream>
usingnamespace std;
int main()
{
do {
int age=9;
cout<<"Pick a number 1-10"<<endl;
cin>> age;
if (age==9)
{
cout<<"correct"<<endl;
}
else
{
cout<<"incorrect"<<endl;
}while (age!=9);
}
}
So I corrected some things but I still get these:
1 In function 'int main()':
2 Line 19: error: expected `while' before '}' token
3 compilation terminated due to -Wfatal-errors.
The errors would be a lot easier to see if you properly indented:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
#include <iostream>
usingnamespace std;
int main()
{
do
{
int age=9;
cout<<"Pick a number 1-10"<<endl;
cin>> age;
if (age==9)
{
cout<<"correct"<<endl;
}
else
{
cout<<"incorrect"<<endl;
}while (age!=9);
}
}
Notice how your 'while' statement is tacked on to the end of the 'else' block, not at the end of the 'do' block.