Guest User

Untitled

a guest
Apr 25th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.68 KB | None | 0 0
  1. #include <windows.h>
  2. #include <stdlib.h>
  3. #include <stdio.h>
  4.  
  5. void main()
  6. {
  7.     srand( GetTickCount() );
  8.     unsigned int guess = rand() % 100;
  9.     int max = 100;
  10.     int min = 0;
  11.     int guesses = 0;
  12.     char c;
  13.  
  14.     while( true )
  15.     {
  16.         printf("I guess %d. Am I too high (H), too low (L) or correct (C)? ", guess );
  17.         scanf( "%c", &c );
  18.         switch( c )
  19.         {
  20.         case 'H':
  21.             max = guess;
  22.             guess = ( max + min ) / 2;
  23.             guesses++;
  24.             break;
  25.         case 'L':
  26.             min = guess;
  27.             guess = ( max + min ) / 2;
  28.             guesses++;
  29.             break;
  30.         case 'C':
  31.             printf("Yay! I did it in %d guesses", guesses);
  32.             Sleep( INFINITE );
  33.             break;
  34.         default:
  35.             printf("Not a valid response");
  36.             break;
  37.         }
  38.     }
  39. }
Add Comment
Please, Sign In to add comment