Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /******************************************************************************
- Welcome to GDB Online.
- GDB online is an online compiler and debugger tool for C, C++, Python, Java, PHP, Ruby, Perl,
- C#, VB, Swift, Pascal, Fortran, Haskell, Objective-C, Assembly, HTML, CSS, JS, SQLite, Prolog.
- Code, Compile, Run and Debug online from anywhere in world.
- *******************************************************************************/
- #include <stdio.h>
- int main()
- {
- // make answer variables
- char ans1, ans2, ans3, ans4, ans5;
- // ask 5 math questions and read in a character input
- printf("What is 5+2?\n");
- printf("a. 6\n");
- printf("b. 7\n");
- printf("c. 3\n");
- printf("d. 2\n");
- printf("e. 1\n");
- scanf("%s", &ans1);
- printf("What is 10+3?\n");
- printf("a. 13\n");
- printf("b. 7\n");
- printf("c. 12\n");
- printf("d. 4\n");
- printf("e. 2\n");
- scanf("%s", &ans2);
- printf("What is 9/3?\n");
- printf("a. 0\n");
- printf("b. 1\n");
- printf("c. 4\n");
- printf("d. 3\n");
- printf("e. 9\n");
- scanf("%s", &ans3);
- printf("What is 5-2?\n");
- printf("a. 6\n");
- printf("b. 7\n");
- printf("c. 3\n");
- printf("d. 2\n");
- printf("e. 52\n");
- scanf("%s", &ans4);
- printf("What is 2*4?\n");
- printf("a. 0\n");
- printf("b. 7\n");
- printf("c. 3\n");
- printf("d. 8\n");
- printf("e. 6\n");
- scanf("%s", &ans5);
- // store a counter and count how many are correct
- int cnt = 0;
- if(ans1=='b') cnt++;
- if(ans2=='a') cnt++;
- if(ans3=='d') cnt++;
- if(ans4=='c') cnt++;
- if(ans5=='d') cnt++;
- // output the numbr of correct answers and the percentage of correct answers
- printf("The number of correct answers out of 5 is: %d\n", cnt);
- printf("Your percentage is: %d\n.", cnt*100/5);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement