Advertisement
Mr_kindle

Number_guessing.c

Oct 13th, 2022 (edited)
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.77 KB | None | 0 0
  1. //The computer will guess the number which is in your mind
  2. #include<stdio.h>
  3. #include<time.h>
  4. int main()
  5. {   int upper_limit = 100,lower_limit = 0,guess,limit;
  6.     char feedback;
  7.  
  8.     srand(time(0));
  9.     printf("You guess any number between 1 and 100 and just put it in your mind\n");
  10.    
  11.    
  12.     while(feedback != 'c')
  13.     {   guess = rand()%(upper_limit - lower_limit+1)+lower_limit;
  14.     //getch();
  15.         printf("\n\nif number %d is too high, press 'h'.\\ if too low press 'l' and if same as your guessed number press 'c'\n", guess);
  16.         scanf(" %c",&feedback);
  17.        
  18.         if (feedback == 'h')
  19.             {
  20.             limit = guess - 1;
  21.             upper_limit = limit;
  22.         }
  23.         else if (feedback == 'l')
  24.             {
  25.             lower_limit = guess +1;
  26.            
  27.         }
  28.     }
  29.     printf("Wow, you guessed the number %d currectly\n",guess);
  30.     return 0;
  31.    
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement