home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / i / intgame.zip / GAME.C next >
Text File  |  1989-01-27  |  3KB  |  92 lines

  1. /*This program solves the problem: find a series of consecutive integers
  2.   that add up to 10,000, and makes it into a game where the user guesses
  3.   the starting integer.
  4.  
  5.   Written by: Dennis E. Henley
  6.   Written:    January 25, 1989
  7.   Language:   Turbo C 2.0          */
  8.  
  9.  
  10. #include <stdio.h>
  11. #define MAX 10000
  12. #define LIMIT 5000
  13.  
  14. main ()
  15. {
  16.     int start, next, sum, reply, try;
  17.  
  18.     for (start = 1; start < 26; ++start)
  19.       printf ("\n");
  20.     printf ("NORASAURUS, INC.\n\n\n");
  21.     printf ("presents\n\n\n");
  22.     printf ("The Amazing Consecutive Integer Game\n\n\n\n");
  23.     printf ("Can you find a series of consecutive integers that\n");
  24.     printf ("add up to %d?\n\n", MAX);
  25.     try = 1;
  26.     reply = 1;
  27.     while (reply == 1) {
  28.       printf ("\nWhat is the first integer in this series?  ");
  29.       scanf ("%d", &start);
  30.       printf ("\n\n");
  31.       sum = start;
  32.       next = start;
  33.         while (sum < 10000) {
  34.           ++next;
  35.           sum = sum + next;
  36.         }
  37.        if (sum == 10000) {
  38.         printf ("CONGRATULATIONS!\n");
  39.         printf ("You have picked the correct starting integer.\n");
  40.         printf ("The integers %d through %d add up to %d.\n\n", start, next, sum);
  41.         }
  42.        else {
  43.         printf ("SORRY.\n");
  44.         printf ("The integers %d through %d do not add up to %d.\n", start, next, MAX);
  45.         printf ("They total %d.\n\n", sum);
  46.        }
  47.       printf ("\n\n");
  48.       printf ("Would you like to play again?\n");
  49.       printf ("1. Play again.     2. Quit.    3. Quit, but give me the answer.\n\n");
  50.       printf ("What would you like to do?   ");
  51.       scanf ("%d", &reply);
  52.       if (reply == 2)
  53.         try = 1;
  54.       if (reply == 3) {
  55.         try = 1;
  56.         for (start = 1; start < LIMIT; ++start) {
  57.             next = start;
  58.             sum = next;
  59.             while (sum < MAX) {
  60.                 ++next;
  61.                 sum = sum + next;
  62.             }
  63.             if (sum == MAX) {
  64.                 printf ("\n");
  65.                 printf ("The consecutive integers %d through %d ", start, next);
  66.                 printf ("total %d.\n", sum);
  67.             }
  68.           }
  69.     }
  70.     ++try;
  71.     if (try == 3) {
  72.         printf ("\nHere's a hint.\n");
  73.         printf ("The starting integer has to be less than 5,000.\n");
  74.       }
  75.       if (try == 5) {
  76.         printf ("\nHere's another hint.\n");
  77.         printf ("There are four sets of consecutive integers that total %d.\n", MAX);
  78.       }
  79.  
  80.  }
  81.   printf ("\n\nThanks for playing the Amazing Consecutive Integer Game,\n");
  82.   printf ("which is my first program in Turbo C.\n");
  83.   printf ("This program is offered free of charge to those who want it\n");
  84.   printf ("But I would like to know how far the program travels,\n");
  85.   printf ("so, if you played it, please send a postcard to:\n\n");
  86.   printf ("Dennis E. Henley\n");
  87.   printf ("5106 N. Mango Avenue\n");
  88.   printf ("Chicago, Illinois 60630\n\n");
  89.   printf ("Thanks. And watch for the next program from Norasaurus, Inc.\n");
  90.  }
  91.  
  92.