Question
June 29, 2010 at 06:49 PM
vineo76

Can someone give me a hint for this C program??

by vineo76 . Updated 16 years, 2 months ago

want to keep track of how many questions the player has answered correctly and incorrectly and display the running totals at the end of the math quiz.

This is a math quiz that prompts the user for how many questions to ask and congrats the user if he gets them correct and corrects him when he gets then incorrect by the way

To keep track of how many questions the user has answered correctly or incorrectly should I use an if statement, a for loop or a while loop? I am thinking of using and if statement. Which kind of statement should I use to do this. The program is below:

#include

main()

{

int x, iNumQuestions, iResponse, iRndNum1, iRndNum2;
srand(time());

printf(“\nPlease enter the number of questions you want: “);
scanf(“%d”, &iNumQuestions);

for ( x = 0; x < iNumQuestions; x++ ) { iRndNum1 = rand() % 10 + 1; iRndNum2 = rand() % 10 + 1; printf("\nWhat is %d - %d: ", iRndNum1, iRndNum2); scanf("%d", &iResponse); if ( iResponse == iRndNum1 - iRndNum2 ){ printf("\nCongrats!!!\n"); } else{ printf("\nThe correct answer is %d\n", iRndNum1 - iRndNum2); } } }

This discussion is locked

All Comments