Guest User

Untitled

a guest
Aug 19th, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 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.  
  17.  
  18. while (flag != 'n')
  19. {
  20. printf ("%d\n", num1);
  21. printf ("Can you guess the number?\nPlease type your first guess.\n");
  22. scanf ( "%d", &guess);
  23. count++;
  24.  
  25. while (guess != num1)
  26. {
  27. if (guess < num1)
  28. {
  29. printf ("Too low, try again.\n");
  30. scanf("%d", &guess);
  31. }
  32.  
  33.  
  34. if (guess > num1)
  35. {
  36. printf ("Too high, try again.\n");
  37. scanf("%d", &guess);
  38. }
  39. }
  40. printf ("Excellent! You guessed the number!\nWould you like to play again? Yes = y, No = n\n");
  41. scanf (" %c", & flag);
  42.  
  43. if (count < 10)
  44. {
  45. printf ("Either you know the secret or you got lucky!\n");
  46. }
  47. if (count > 10)
  48. {
  49. printf ("You should be able to do better!\n");
  50. }
  51. if (count == 10)
  52. {
  53. printf ("Aha! You know the secret!");
  54. }
  55.  
  56. if (flag == 'y')
  57. {
  58. num1 = randomnumbers();
  59. count = 0;
  60. }
  61. }
  62.  
  63. return 0;
  64. }
  65.  
  66. int randomnumbers()
  67. {
  68. return (1 + rand() % 1000);
  69. }
Add Comment
Please, Sign In to add comment