While loop to repeat program not working

My program is a guessing game where the user inputs numbers a maximum of three times to guess the correct number. I wanted to add a loop so that the program would repeat the game infinitely after the guesses from the previous game had been made, so I added the while loop where it says while (i >= 0). But every time I run the program, on any IDE, it refuses to repeat the program, and I'm not sure what I did wrong.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int main (void)
{
    srand(time(0));
    int i = 0;
    while (i >= 0)
    {
    int x = (rand() % 50) + 1;
    int guess;
    int counter = 1;
    printf("I am thinking of a number between 1 and 50. Can you guess what it is?\n");
    printf("Please enter a guess: ");
    scanf(" %d", &guess);

    while (counter <= 3)
    {
        if (counter < 3 && guess !=x)
         {printf("Sorry, it isn't %d\n", guess);
          printf("Please enter a guess: ");
          scanf(" %d", &guess);}
        if (guess == x)
          {printf("Correct! I was thinking of %d!\n", guess);}
        if (counter == 3 && guess != x)
         {printf("You lose! The number I was thinking of is %d\n", x);}
        counter = counter + 1;
    }
    i++;
    getchar();getchar();
    return 0;
    }
}
closed account (2b5z8vqX)
I'm not sure what I did wrong.

A return statement is the last statement in the outer while loop's compound statement. This likely would have been noticed if you were to have properly indented your source code.
return 0; should be outside the loop
Argh, I should have known it was that simple. Thanks, I've got it to work now.
Topic archived. No new replies allowed.