I just need some help with my program that im having trouble fixing, here is the
ID: 3534792 • Letter: I
Question
I just need some help with my program that im having trouble fixing, here is the problem and code.
Design and implement an application that performs flashcard testing of simple mathematical problems. Allow the user to pick the category, Addition, Subtraction, Multiplication, or Division from a menu displayed on the screen. A problem is displayed by generating 2 random numbers. You determine the size of the numbers to be generated. The user is to input the answer, and the program will tell them if it is right or wrong. Ask user if they want to do another. Keep score of the user’s score of correct answers and the number of problems presented. Include the pseudocode.
#include <stdio.h>
#include <stdlib.h>
#define RAND_MAX 10
int main()
{
int rand1, rand2;
int prompt, guess, fin_prompt;
while (1)
{
printf("Please pick the category: 1. Addition 2. Subtraction 3. Muktiplication 4. Division ");
scanf("%d", &prompt);
rand1 = rand() / RAND_MAX;
rand2 = rand() / RAND_MAX;
printf("Please input the answer: ");
scanf("%d", &guess);
switch(prompt)
{
case 1 : if (guess == rand1 + rand2)
printf("Correct!");
else
printf("Wrong!");
break;
case 2 : if (guess == rand1 - rand2)
printf("Correct!");
else
printf("Wrong!");
break;
case 3 : if (guess == rand1 * rand2)
printf("Correct!");
else
printf("Wrong!");
break;
case 4 : if (guess == rand1 / rand2)
printf("Correct!");
else
printf("Wrong!");
break;
}
printf("select: 1. try again 2. quit ");
scanf("%d", &fin_prompt);
if(fin_prompt == 1)
continue;
else if(fin_prompt == 2)
break;
else
printf("Invalid input!");
}
return 0;
}
Explanation / Answer
#include<stdio.h>
#include<stdlib.h>
#define RAND_MAX 10 // this is the maximum random number as of now.
int main(){
int rand1,rand2;
int prompt,guess,fin_prompt;
while(1){
printf("please pick the category: 1. Addition 2. Subtraction 3. Multiplication 4.Division");
scanf("%d",&prompt);
rand1 = rand() / RAND_MAX;
rand2 = rand() /RAND_MAX;
printf("please input the answer: ");
scanf("%d",&guess);
switch(prompt){
case 1 : if(guess == rand1+rand2)
printf("Correct!!");
else
printf("Wrong!!");
break;
case 2 : if(guess == rand1-rand2)
printf("Correct!!");
else
printf("Wrong!!");
break;
case 3 : if(guess == rand1*rand2)
printf("Correct!!");
else
printf("Wrong!!");
break;
case 4 : if(guess == rand1/rand2)
printf("Correct!!");
else
printf("Wrong!!");
break;
}
printf("select: 1. try again 2. quit");
scanf("%d",&fin_prompt);
if(fin_prompt == 1)
continue;
else if(fin_prompt == 2)
break;
else
printf("invalid input!!!")
}
return 0;
}