Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- //
- int
- main(int argc, char **argv) {
- printf("Welcome to the High Low game...\n");
- // Write your implementation here...
- int going = 1;
- while(going)
- {
- printf("Think of a number between 1 and 100 and press <enter>\n");
- int low = 1, high = 100;
- char result;
- while(high >= low)
- {
- getchar();
- int mid = (low+high)/2;
- printf("Is it higher than %d? (y/n)\n", mid);
- scanf("%c", &result);
- if(result == 'y')
- {
- low = mid+1;
- }
- else if(result == 'n')
- {
- high = mid-1;
- }
- else
- {
- printf("BEEP! BOOP! INPUT NOT RECOGNIZED!!!\n");
- exit(0);
- }
- }
- printf("\n>>>>>> The number is %d\n\n", high+1);
- printf("Do you want to continue playing (y/n)?");
- scanf("%c", &result);
- printf("%c\n", result);
- if(result == 'n')
- {
- going = 0;
- printf("Thanks for playing!!!\n");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment