-
Question bout my work
Code:
printf ("1.Enter the number of questions to be asked for this round of the quiz\n\n"); //Number of quizs
printf ("2.Start quiz\n\n"); //Run questions
printf ("3.Display the number of questions answered (i) correct and (ii) incorrect\n\n"); //Display results
printf ("4.Exit Program\n\n"); //Exit Program
printf ("Enter option : \n\n");
scanf ("%d", &Selection);
if (Selection == 1)
{
printf ("How many Question would you like to be asked? [ 1 - 4 ]\n");
scanf ("%d\n", &SelectionQuestions);
}
else if (Selection == 2)
{
printf (" --------------------------\n");
printf (" -[-[ Question Begin ]-]- \n");
printf (" --------------------------\n\n");
printf ("----------------\n");
printf ("- 1st Question -\n");
printf ("----------------\n");
printf ("What is 1 + 1 = ?\n");
scanf ("%d", &answer);
if (answer ==2)
printf("\nYou got it right!!!\n\n\n");
else
printf("\nThe answer is incorrect , the correct answer is 2\n\n\n");
printf ("----------------\n");
printf ("- 2nd Question -\n");
printf ("----------------\n");
printf("What is 10 - 5 = ?\n");
scanf("%d",&answer);
if (answer ==5)
printf("\nYou got it right!!!\n\n\n");
else
printf("\nThe answer is incorrect , the correct answer is 5\n\n\n");
printf ("----------------\n");
printf ("- 3rd Question -\n");
printf ("----------------\n");
printf("What is 3+4-10= ?\n");
scanf("%d",&answer);
if ( answer ==-3)
printf("\nYou got it right!!!\n\n\n");
else
printf("\nIncorrect! The correct answer is -3\n\n\n");
printf ("----------------\n");
printf ("- 4th Question -\n");
printf ("----------------\n");
printf("What is 10+20+4-10 = ?\n");
scanf("%d",&answer);
if ( answer ==24)
printf("\nYou got it right!!!\n\n\n");
else
printf("\nIncorrect! The correct answer is 24\n\n\n");
}
system("PAUSE");
return 0;
}
tis part of my assignment.
i cant figure the part where i select how many question to be asked that part.
can any1 just tutor me or show me any tutorial which is similar to it?
-
A few ideas:
- try to move the questions from the main to a function, and in main you could use a loop for the menu, and instead of if else, a switch might look nicer.
- you probably should ask first for the number of questions before showing the the menu, otherwise someone might start the quiz without specifying the number of questions.
- send the SelectionQuestions as a parameter to the function and then, depending on the value, call the appropriate number of questions.
-
Add some random numbers for the arithmetic to be done on.
-
You should also be checking the return value of scanf. It will return the number of items read, you should make sure it is reading in the same amount as variables you have after the format string.
-
What you need to do first of all is fix your indentation. It's impossible to see what belongs where.