Code:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#define ADD 1
#define MULT 2
int main() {
int choice, roundscore, totalscore, count1, count2, x, y, maxnum, answer, correct, i, z, guess, guessnum;
srand(time(0));
while (choice!=4){
printf("Please make a selection from the following:\n");
printf("1. Play Arithmetic Game.\n");
printf("2. Play Guessing Game.\n");
printf("3. Print Score.\n");
printf("4. Quit.\n");
scanf("%d", &choice);
switch(choice){
case 1:
printf("What is the maximum number you'd like?\n");
scanf("%d", &maxnum);
for (i=0; i<10; i++){
x = rand() % maxnum;
y = rand() % maxnum;
printf("What is %d+%d\n", x, y);
scanf("%d\n" , &answer);
correct = x+y;
if (answer == correct){
printf("Correct, great job!\n");
count1++;
roundscore += count1;
}
else
printf("Sorry, that's incorrect, the answer is %d\n", correct);
}//end case1 for
printf("Your score for the round is %d.\n", roundscore);
totalscore += roundscore;
break;
case 2:
guessnum = rand() % 100;
for(z=0; z<17; z++){
printf("Enter a guess!\n");
scanf("%d\n", &guess);
if (guess != guessnum && guess > guessnum){
printf("Your guess is to high, guess again.\n");
count2++;
}
if (guess != guessnum && guess < guessnum){
printf("Your guess is to low, guess again\n");
count2++;
}
if (guess == guessnum){
printf("Great, you guessed the correct number %d in %d guesses.\n", guessnum, count2);
count2++;
break;
}
}// end case 3 for loop
break;
case 3:
printf("Your total score is %d.\n", totalscore);
break;
case 4:
exit(0);
default:
printf("You have made an invalid choice.\n");
}
}//END WHILE LOOP
return 0;
}