Advertisement
Holey_yan

20140506_KUAS_VisualC++_UltimatePassword

May 6th, 2014
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.20 KB | None | 0 0
  1. /************************************/
  2. /** 20140506 Ultimate Password     **/
  3. /** Maker  : Yan                   **/
  4. /** E-Mail : ssas1115577@gmail.com **/
  5. /** Date   : 2014/05/26 am.10:03   **/
  6. /************************************/
  7.  
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10. #include <time.h>
  11.  
  12. int compare(int, int);
  13.  
  14. void main()
  15. {
  16.     printf("-------------Start Game !-------------\n");
  17.     srand(time(NULL));
  18.     int random = rand() % (100 - 0 + 1) + 0;
  19.     int max_limit = 100, min_limit = 1;
  20.     while(1)
  21.     {
  22.         printf("The range is %d to %d.\n", min_limit, max_limit);
  23.         printf("Enter a number of you guess: ");
  24.         int input = 0;
  25.         scanf("%d", &input);
  26.         switch(compare(input, random))
  27.         {
  28.             case 0:
  29.                 printf("The number is smaller.\n");
  30.                 max_limit = input;
  31.                 break;
  32.             case 1:
  33.                 printf("The number is larger.\n");
  34.                 min_limit = input;
  35.                 break;
  36.             case 2:
  37.                 printf("\nComgratulations, you get the number !\n");
  38.                 printf("--------------End Game !--------------\n");
  39.                 system("pause");
  40.                 return;
  41.         }
  42.     }
  43. }
  44.  
  45. int compare(int input, int random)
  46. {
  47.     if(input > random)
  48.     {
  49.         return 0;
  50.     }
  51.     else if(input < random)
  52.     {
  53.         return 1;
  54.     }
  55.     else if(input = random)
  56.     {
  57.         return 2;
  58.     }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement