this should be my output:
Please enter a number from 0 to 100:
50
You guessed correctly in 1 try!Congratulations!
Play again?
Y //Yes
Please enter a number from 0 to 100:
Expand|Select|Wrap|Line Numbers
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
- int main()
- {
- int guessed_number, random_number, counter=0;
- char symbol='*',choice,choice2;
- srand(time(NULL));
- random_number= rand()%100 + 1;
- printf("*************************************************");
- printf("\n%-14cWELCOME TO THE GAME!%15c",symbol,symbol);
- printf("\n%-24c%25c",symbol,symbol);
- printf("\n%-24c%25c",symbol,symbol);
- printf("\n%-22cSTART%22c",symbol,symbol);
- printf("\n%-22cQUIT%23c",symbol,symbol);
- printf("\n*************************************************\n");
- scanf("%c",&choice);
- if(choice=='s')
- {
- printf("Please enter a number from 0 to 100:");
- while(1)
- {
- counter ++;
- scanf("%d",&guessed_number);
- if(guessed_number<random_number)
- printf("Your guess is too low.Guess again.\n");
- if(guessed_number>random_number)
- printf("Your guess is too high. Guess again.\n");
- if(guessed_number==random_number)
- {
- printf("You guessed correctly in %dtries! Congratulations!",counter);
- break;
- }
- }
- }
- else
- {
- printf("Bye! See you next time!");
- }
- }