#include <iostream>
#include <cstdlib>
usingnamespace std;
int main ()
{
int answer; int question=0;
cout << "Guess the number i am thinking about\n";
while (question<=10, question++)
do {
cout << "Insert the number other than " << question << ":";
cin >> answer;
if (answer==5)
cout << "You got me babe";
if (question==10)
cout << "You are more patient than me, you win";
}
return 0;
}
but when i compile it, syntax error on return
i am sorry for this, i am only a noob :3
my question is, is there anything wrong with my solution?
You're kind of combining a while loop with a do-while loop to make a while-do loop, which doesn't exist. Just remove "do" and it should work, or put the while part after the closing brace.
#include <iostream>
#include <cstdlib>
usingnamespace std;
int main ()
{
int answer; int question=0;
cout << "Guess the number i am thinking about\n";
while (question<=10, question++)
cout << "Insert the number other than " << question << ":";
cin >> answer;
if (answer==5)
cout << "You got me babe";
if (question==10)
cout << "You are more patient than me, you win";
}
return 0;
}
You deleted the opening brace when you deleted the "do". Put that back and it should be fine. But why are you telling them to guess any number other than the number you're incrementing, rather than 5 every time? The question seems to be telling you to always tell them to not guess 5.
#include <iostream>
#include <cstdlib>
usingnamespace std;
int main ()
{
int answer; int question=0;
cout << "Guess the number i am thinking about\n";
do {
cout << "Insert the number other than " << question++ << ":";
cin >> answer;
if (answer==5)
cout << "You got me babe\n";
if (question==10)
cout << "You are more patient than me, you win\n";
}
while (question!=10, answer!=5);
return 0;
}