Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <math.h>
- int addition();
- int main()
- {
- int i = 50;
- int userAns;
- int score =0;
- printf("Hello! Select the game mode you would like to play by choosing the correct corresponding number:"
- " \n 1) addition\n 2) subtraction\n2");
- scanf("%d",&userAns);
- if(userAns==1)
- {
- while(i>1)
- {
- addition();
- --i;
- printf("\nYou have %d rounds left", i);
- }//loop for 50 round
- }//close addition branch
- if(userAns==2)
- {
- while(i>1)
- {
- subtraction();
- --i;
- printf("\nYou have %d rounds left", i);
- }//loop for 50 rounds
- }//close subtraction branch
- }//end main
- int addition()
- {
- int a;
- int b;
- int ans;
- a = (rand()%10);
- b = (rand()%10);
- printf("\nWhat is the sum of %d + %d ?", a,b);
- scanf("%d",&ans);
- if((a+b)==ans)
- {
- printf("Hooray! That was correct :)");
- }
- if((a+b)!=ans)
- {
- printf("Sorry! That was incorrect :(");
- }
- return 0;
- }
- int subtraction()
- {
- int a;
- int b;
- int ans;
- a = (rand()%10);
- b = (rand()%10);
- printf("\nWhat is the sum of %d - %d ?", a,b);
- scanf("%d",&ans);
- if((a-b)==ans)
- {
- printf("Hooray! That was correct :)");
- }
- if((a-b)!=ans)
- {
- printf("Sorry! That was incorrect :(");
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement