Do-while looping help!

Hi! I have to make a code that keeps asking the user to guess a number between 1 and 10 until the user enters a 4. my current code isn't working but i'm not sure why that is... can somebody help me identify what i'm doing wrong/suggest how i can fix it?

#include<iostream>
#include<cstdlib>
#include<ctime>

using namespace std;

int main()
{
srand(time(0));
int time = rand() % 10 + 1;;
int guess;

char answer;
cout << "Guess a number between 1 and 10: ";
cin >> guess;

while (guess != 4)
{
if (guess >= 1 && guess <= 3)
{
cout << "Wrong! Try again.";
cin >> guess;
}
if (guess >= 5 && guess <= 10)
{
cout << "Wrong! Try again.";
cin >> guess;
}
if (guess == 4)
{
cout << "You guessed it";
}
else {
cout << "Please follow directions!";
}
return 0;
}
The return 0 is in the while block. You need to place the return 0 outside the while block and also add a "}" sign to indicate the end of the main function
Topic archived. No new replies allowed.