Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <windows.h>
- #include <stdlib.h>
- #include <stdio.h>
- void main()
- {
- srand( GetTickCount() );
- unsigned int guess = rand() % 100;
- int max = 100;
- int min = 0;
- int guesses = 0;
- char c;
- while( true )
- {
- printf("I guess %d. Am I too high (H), too low (L) or correct (C)? ", guess );
- scanf( "%c", &c );
- switch( c )
- {
- case 'H':
- max = guess;
- guess = ( max + min ) / 2;
- guesses++;
- break;
- case 'L':
- min = guess;
- guess = ( max + min ) / 2;
- guesses++;
- break;
- case 'C':
- printf("Yay! I did it in %d guesses", guesses);
- Sleep( INFINITE );
- break;
- default:
- printf("Not a valid response");
- break;
- }
- }
- }
Add Comment
Please, Sign In to add comment