Guest User

Untitled

a guest
Jan 9th, 2017
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. //
  4.  
  5. int
  6. main(int argc, char **argv) {
  7. printf("Welcome to the High Low game...\n");
  8.  
  9. // Write your implementation here...
  10.  
  11. int going = 1;
  12. while(going)
  13. {
  14. printf("Think of a number between 1 and 100 and press <enter>\n");
  15. int low = 1, high = 100;
  16. char result;
  17. while(high >= low)
  18. {
  19. getchar();
  20. int mid = (low+high)/2;
  21. printf("Is it higher than %d? (y/n)\n", mid);
  22. scanf("%c", &result);
  23. if(result == 'y')
  24. {
  25. low = mid+1;
  26. }
  27. else if(result == 'n')
  28. {
  29. high = mid-1;
  30. }
  31. else
  32. {
  33. printf("BEEP! BOOP! INPUT NOT RECOGNIZED!!!\n");
  34. exit(0);
  35. }
  36. }
  37. printf("\n>>>>>> The number is %d\n\n", high+1);
  38. printf("Do you want to continue playing (y/n)?");
  39. scanf("%c", &result);
  40. printf("%c\n", result);
  41. if(result == 'n')
  42. {
  43. going = 0;
  44. printf("Thanks for playing!!!\n");
  45. }
  46. }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment