how to limit the insertion times to this prog

I want to allow the user to input only three values to this program after that I want the program to exit. please help.

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
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int main ()
{
  int iSecret, iGuess;

  /* initialize random seed: */
  srand ( time(NULL) );

  /* generate secret number: */
  iSecret = rand() % 10 + 1;

  do {
    printf ("Guess the number (1 to 10): ");
    scanf ("%d",&iGuess);
    if (iSecret<iGuess) puts ("The secret number is lower");
    else if (iSecret>iGuess) puts ("The secret number is higher");
  } while (iSecret!=iGuess);

  puts ("Congratulations!");
  return 0;
}
Could you not add another condition to your do...while loop where you keep a counter that counts from 0 - 3 so
1
2
3
4
5
6
7
do {
       printf("Guess the number (1 to 10): ");
       scanf("%d", &iGuess);
       ...
       ...
       counter++;
} while (iSecret!=iGuess && counter < 3);


and just initialize counter to 0.
thank u mate.
Topic archived. No new replies allowed.