Advertisement
Guest User

Guess a number

a guest
May 16th, 2016
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.63 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <math.h>
  4. #include <time.h>
  5.    
  6. int main()
  7. {  
  8.     int guess;
  9.     int attempts;
  10.     srand(time(NULL));
  11.     int special_number = rand() % (10000 +1 - 0) + 0;
  12.    
  13.     for(attempts=1; guess!=special_number; attempts++){
  14.         printf("Please guess the random number\nBetween 0 and 10000! ");
  15.         scanf(" %d", &guess);
  16.         if(guess==special_number){
  17.             printf("Congratulations! The number was %d\nIt took you %d attempts.\n", special_number, attempts);
  18.         }else if(guess<special_number){
  19.             printf("Too low! Guess higher!\n");
  20.         }else{
  21.             printf("Too high! Guess lower!\n");
  22.         }
  23.     }
  24.        
  25.     return 0;
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement