46 lines
1.4 KiB
C
46 lines
1.4 KiB
C
|
#include <stdio.h>
|
||
|
#include <stdlib.h>
|
||
|
#include <string.h>
|
||
|
#include <stdbool.h>
|
||
|
#include <time.h>
|
||
|
|
||
|
int fnr() {
|
||
|
return (rand() %(5-1))+1;
|
||
|
}
|
||
|
|
||
|
int main() {
|
||
|
srand(time(0));
|
||
|
printf("Number\n");
|
||
|
printf("Creative Computing Morristown, New Jersey\n");
|
||
|
printf("You have 100 points. By guessing numbers from 1 to 5, you\n");
|
||
|
printf("can gain or lose points depending upon how close you get to\n");
|
||
|
printf("a random number selected by the computer.\n");
|
||
|
printf("You occasionally will get a jackpot which will double(!)\n");
|
||
|
printf("Your point count. You win when you get 500 points\n");
|
||
|
printf("Guess a number from 1 to 5 ");
|
||
|
int points = 100;
|
||
|
while (points < 500) {
|
||
|
printf("You have %d points.\n", points);
|
||
|
char input[5];
|
||
|
fgets(input, 5, stdin);
|
||
|
int guess = atoi(input);
|
||
|
int r = fnr();
|
||
|
int s = fnr();
|
||
|
int t = fnr();
|
||
|
int u = fnr();
|
||
|
int v = fnr();
|
||
|
if (guess == r) {
|
||
|
points = points - 5;
|
||
|
} else if (guess == s) {
|
||
|
points = points + 5;
|
||
|
} else if (guess == t) {
|
||
|
points = points + points;
|
||
|
printf("YOU HIT THE JACKPOT!!!");
|
||
|
} else if (guess == u) {
|
||
|
points = points + 1;
|
||
|
} else if (guess == v) {
|
||
|
points = points - (points * .5);
|
||
|
}
|
||
|
}
|
||
|
printf("!!!!YOU WIN!!!! WITH %d POINTS.\n", points);
|
||
|
}
|