Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //The computer will guess the number which is in your mind
- #include<stdio.h>
- #include<time.h>
- int main()
- { int upper_limit = 100,lower_limit = 0,guess,limit;
- char feedback;
- srand(time(0));
- printf("You guess any number between 1 and 100 and just put it in your mind\n");
- while(feedback != 'c')
- { guess = rand()%(upper_limit - lower_limit+1)+lower_limit;
- //getch();
- 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);
- scanf(" %c",&feedback);
- if (feedback == 'h')
- {
- limit = guess - 1;
- upper_limit = limit;
- }
- else if (feedback == 'l')
- {
- lower_limit = guess +1;
- }
- }
- printf("Wow, you guessed the number %d currectly\n",guess);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement