Guest User

Untitled

a guest
Aug 18th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <time.h>
  4.  
  5. int randomnumbers ();
  6.  
  7. int main ()
  8. {
  9. int guess, num1, count;
  10. char flag = 'y';
  11. printf ("I have a number between 1 and 1000.\n");
  12. srand (time(0));
  13. num1 = randomnumbers();
  14. count = 0;
  15.  
  16. while (flag != 'n')
  17. {
  18. printf ("Can you guess the number?\nPlease type your first guess.\n");
  19. scanf ( "%d", &guess);
  20. count++;
  21.  
  22. while (guess != num1)
  23. {
  24. if (guess < num1)
  25. {
  26. printf ("Too low, try again.\n");
  27. scanf("%d", &guess);
  28. }
  29.  
  30. if (guess > num1)
  31. {
  32. printf ("Too high, try again.\n");
  33. scanf("%d", &guess);
  34. }
  35. }
  36. printf ("Excellent! You guessed the number!\nWould you like to play again? Yes = y, No = n\n");
  37. scanf (" %c", & flag);
  38.  
  39. if (flag == 'y')
  40. {
  41. num1 = randomnumbers();
  42. count = 0;
  43. }
  44. }
  45.  
  46. return 0;
  47. }
  48.  
  49. int randomnumbers()
  50. {
  51. return (1 + rand() % 1000);
  52. }
Add Comment
Please, Sign In to add comment