Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- #include <stdio.h>
- #include <time.h>
- int randomnumbers ();
- int main ()
- {
- int guess, num1, count;
- char flag = 'y';
- printf ("I have a number between 1 and 1000.\n");
- srand (time(0));
- num1 = randomnumbers();
- count = 0;
- while (flag != 'n')
- {
- printf ("Can you guess the number?\nPlease type your first guess.\n");
- scanf ( "%d", &guess);
- count++;
- while (guess != num1)
- {
- if (guess < num1)
- {
- printf ("Too low, try again.\n");
- scanf("%d", &guess);
- }
- if (guess > num1)
- {
- printf ("Too high, try again.\n");
- scanf("%d", &guess);
- }
- }
- printf ("Excellent! You guessed the number!\nWould you like to play again? Yes = y, No = n\n");
- scanf (" %c", & flag);
- if (flag == 'y')
- {
- num1 = randomnumbers();
- count = 0;
- }
- }
- return 0;
- }
- int randomnumbers()
- {
- return (1 + rand() % 1000);
- }
Add Comment
Please, Sign In to add comment