I'm trying to develop a quiz type math game in which the user has to solve on 1-5 questions. I want to add a counter that will display all the correct and incorrect answers at the end of the quiz, so far I have been doing it using if else statement, but I feel like there's should be a more efficient way of doing it. My code:
if ( questions == 2 )
{
printf (" What is 2 + 2\n");
scanf("%d",&A1);
if( A1 == 4 )
{
correct ++;
}
else
{
incorrect ++;
}
printf (" What is 5 + 2\n");
scanf("%d",&A2);
if( A2 == 7 )
{
correct ++;
}
else
{
incorrect ++;
}
}
Here's the code i have the same thing written 5 times for each option that the user can pick. All help is greatly appreciated, thanks in advance!