Advertisement
Guest User

Untitled

a guest
Feb 24th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. int main(void)
  2. {
  3. int iRandomNum;
  4. int iGuess;
  5. srand(time(NULL));
  6.  
  7. iRandomNum = (rand() % 10);
  8. printf("Guess a number between 1 and 10:");
  9. scanf("%d", &iGuess);
  10.  
  11. // isdigit function expects a character so the guess value has to be ascii value of the digit character
  12. iGuess += 48;
  13. if (isdigit(iGuess)){
  14. iGuess -=48; // change back to the original value for comparison with random number
  15. if (iGuess == iRandomNum){
  16. printf("You Guessed Correctlyn");
  17. }
  18. else{
  19. printf("The correct answer was %dn",iRandomNum);
  20. printf("You guessed %dn",iGuess);
  21. }
  22. }
  23. else{
  24. printf("This is not a digit!n");
  25. }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement