Guest User

Untitled

a guest
Jul 19th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.49 KB | None | 0 0
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <time.h>
  4. int
  5. main (void)
  6. {
  7. int n;
  8. int g;
  9. char c;
  10. srand (time (NULL));
  11. n = 1 + (rand () % 10);
  12. puts ("I'm thinking of a number between 1 and 10.");
  13. puts ("Try to guess it:");
  14. while (1)
  15. {
  16. if (scanf ("%d", &g) != 1)
  17. {
  18. /* ignore one char, in case user gave a non-number */
  19. scanf ("%c", &c);
  20. continue;
  21. }
  22. if (g == n)
  23. {
  24. puts ("Correct!");
  25. return 0;
  26. }
  27. puts (" That 's not my number. Try another guess:");
  28. }
  29. }
Add Comment
Please, Sign In to add comment