Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
- int input();
- int addition(int number1, int number2);
- int multiplication(int number1, int number2);
- int main()
- {
- time_t t;
- int number1, number2, answer, userAnswer;
- int score = 0;
- int prevScore = 0;
- int i = 0;
- char optionTwo = 'E';
- char option;
- int none[5];
- int ntwo[5];
- srand((unsigned)time(&t));
- while(optionTwo == 'E')
- {
- option = input();
- switch(option)
- {
- case 'A': for(i=0;i<5;i++)
- {
- number1 = rand()%10;
- number2 = rand()%10;
- answer = addition(number1,number2);
- printf("\n\nYour current score is: %d of %d\n", score, i);
- printf("What is %d + %d?\n", number1, number2);
- printf("Your answer:");
- scanf("%d", &userAnswer);
- if (answer == userAnswer)
- {
- printf("Correct!\n");
- score = prevScore + 1;
- prevScore = score;
- }
- else
- {
- printf("Incorrect. The correct answer was %d\n\n", answer);
- none[i] = number1;
- ntwo[i] = number2;
- }
- }
- break;
- case 'M': for(i=0;i<5;i++)
- {
- number1 = rand()%10;
- number2 = rand()%10;
- answer = multiplication(number1,number2);
- printf("\n\nYour current score is: %d\n", score);
- printf("What is %d x %d?\n", number1, number2);
- printf("Your answer:");
- scanf("%d", &userAnswer);
- if (answer == userAnswer)
- {
- printf("Correct!\n");
- score = prevScore + 1;
- prevScore = score;
- }
- else
- {
- printf("Incorrect. The correct answer was %d\n\n", answer);
- none[i] = number1;
- ntwo[i] = number2;
- }
- }
- break;
- case 'Q': printf("Thank your for playing.");
- return(0);
- default: printf("You entered an invalid option. The program will now terminate.\n");
- return (0);
- }
- printf("\n\nYour total score is: %d of %d. You got the following questions wrong.\n", score, i);
- for(i=0;i<5;i++)
- {
- printf("Question [i]: none[i]+ntwo[i]");
- }
- printf("Press (E) to exit this session.");
- printf("Your choice:");
- scanf(" %c", &optionTwo);
- }
- return 0;
- }
- int input()
- {
- char option;
- printf("\n\n**************************************************************************************************************\n");
- printf("* ~~ Math Flash Card Game ~~ *\n");
- printf("* *\n");
- printf("* Please choose what type of game mode you would like to eneter. *\n");
- printf("* *\n");
- printf("* (A) Addition *\n");
- printf("* (M) Multiplication *\n");
- printf("* (Q) Quit *\n");
- printf("* *\n");
- printf("**************************************************************************************************************\n");
- printf("Your option:");
- scanf("%c", &option);
- return option;
- }
- int addition(int number1, int number2)
- {
- int answer;
- answer = number1 + number2;
- return answer;
- }
- int multiplication(int number1, int number2)
- {
- int answer;
- answer = number1 * number2;
- return answer;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement