Guest User

Guess a number

a guest
May 16th, 2016
195
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×