Advertisement
AhnafAbdullah27

Magic Number: C

May 29th, 2020
1,502
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.37 KB | None | 0 0
  1. #include "stdafx.h"
  2. #pragma warning(suppress : 4996)
  3.  
  4. int getguess(int a);
  5.  
  6. int magicnumber = 299;
  7.  
  8. int main(void)
  9. {
  10.     char dummyvar;
  11.  
  12.     int n;
  13.     int g;
  14.    
  15.     printf("Hi! Try and guess what number I'm thinking of! [Y/N]");
  16.     scanf("%c", &dummyvar);
  17.     printf("Hah! Obviously you do want to guess what number I'm thinking of! Why else would you open this application anyway... Let's start. ");
  18.    
  19.     for (n=1; n<11; n=n+1)
  20.     {
  21.         g = getguess(n);
  22.  
  23.         if (g == magicnumber)
  24.         {
  25.             printf("RIGHT! You got it in %d tries! That's really the number I was thinking of! Great job! ", n);
  26.         }
  27.         if (g > magicnumber)
  28.         {
  29.             printf("Hmm... Your guess is higher than the number I'm thinking of... Do try again ");
  30.         }
  31.         if (g < magicnumber)
  32.         {
  33.             printf("Hmm... Your guess is lower than the number I'm thinking of... Do try again ");
  34.         }
  35.  
  36.         if (n == 10)
  37.         {
  38.             printf("Stop! It is clear to me that you will never be able to guess the number I was thinking of! So I will declare it to you myself, it was %d... Now, Farewell!", magicnumber);
  39.         }
  40.            
  41.     }
  42.  
  43.    
  44.     return 0;
  45. }
  46.  
  47. int getguess(int a)
  48. {
  49.     int guess;
  50.     printf("Soo, Guess #%d, What do you think the number is?", a);
  51.     scanf("%d", &guess);
  52.  
  53.     return guess;
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement