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 >
Wrap
Text File
|
1989-01-27
|
3KB
|
92 lines
/*This program solves the problem: find a series of consecutive integers
that add up to 10,000, and makes it into a game where the user guesses
the starting integer.
Written by: Dennis E. Henley
Written: January 25, 1989
Language: Turbo C 2.0 */
#include <stdio.h>
#define MAX 10000
#define LIMIT 5000
main ()
{
int start, next, sum, reply, try;
for (start = 1; start < 26; ++start)
printf ("\n");
printf ("NORASAURUS, INC.\n\n\n");
printf ("presents\n\n\n");
printf ("The Amazing Consecutive Integer Game\n\n\n\n");
printf ("Can you find a series of consecutive integers that\n");
printf ("add up to %d?\n\n", MAX);
try = 1;
reply = 1;
while (reply == 1) {
printf ("\nWhat is the first integer in this series? ");
scanf ("%d", &start);
printf ("\n\n");
sum = start;
next = start;
while (sum < 10000) {
++next;
sum = sum + next;
}
if (sum == 10000) {
printf ("CONGRATULATIONS!\n");
printf ("You have picked the correct starting integer.\n");
printf ("The integers %d through %d add up to %d.\n\n", start, next, sum);
}
else {
printf ("SORRY.\n");
printf ("The integers %d through %d do not add up to %d.\n", start, next, MAX);
printf ("They total %d.\n\n", sum);
}
printf ("\n\n");
printf ("Would you like to play again?\n");
printf ("1. Play again. 2. Quit. 3. Quit, but give me the answer.\n\n");
printf ("What would you like to do? ");
scanf ("%d", &reply);
if (reply == 2)
try = 1;
if (reply == 3) {
try = 1;
for (start = 1; start < LIMIT; ++start) {
next = start;
sum = next;
while (sum < MAX) {
++next;
sum = sum + next;
}
if (sum == MAX) {
printf ("\n");
printf ("The consecutive integers %d through %d ", start, next);
printf ("total %d.\n", sum);
}
}
}
++try;
if (try == 3) {
printf ("\nHere's a hint.\n");
printf ("The starting integer has to be less than 5,000.\n");
}
if (try == 5) {
printf ("\nHere's another hint.\n");
printf ("There are four sets of consecutive integers that total %d.\n", MAX);
}
}
printf ("\n\nThanks for playing the Amazing Consecutive Integer Game,\n");
printf ("which is my first program in Turbo C.\n");
printf ("This program is offered free of charge to those who want it\n");
printf ("But I would like to know how far the program travels,\n");
printf ("so, if you played it, please send a postcard to:\n\n");
printf ("Dennis E. Henley\n");
printf ("5106 N. Mango Avenue\n");
printf ("Chicago, Illinois 60630\n\n");
printf ("Thanks. And watch for the next program from Norasaurus, Inc.\n");
}