Question: (Write a program, and show the output too ) C programming You will be writing a simple Bee application. There are five questions. The application
(Write a program, and show the output too) C programming
You will be writing a simple Bee application. There are five questions. The application will display question 1, wait for the user to type a response, it checks if it is correct or not. if correct, it will increment the score by one. otherwise, it will go ahead with the next question. This is repeated for four other questions.
The following is the C code for the program:
// this is a quiz
#include
// this is the question 1 int Question_1() { printf ("What is the capital of USA? 1. Atlanta 2. Washington DC 3. New York 4. Chicago "); int correctAnswer = 2; int userResponse; scanf ("%d", &userResponse); if (correctAnswer == userResponse) return 1; else return 0; }
// this is the question 2 int Question_2() { printf ("Where is Louisiana? 1. Canada 2. France 3. USA 4. Mexico "); int correctAnswer = 3; int userResponse; scanf ("%d", &userResponse); if (correctAnswer == userResponse) return 1; else return 0; }
// this is the question 3 int Question_3() { printf ("What is the capital of United Kingdom? 1. London 2. Scotland 3. Birmingham 4. Heathre "); int correctAnswer = 1; int userResponse; scanf ("%d", &userResponse); if (correctAnswer == userResponse) return 1; else return 0; }
// this is the question 4 int Question_4() { printf ("What is the capital of New York? 1. Syracuse 2. Albany 3. Buffalo 4. New York City "); int correctAnswer = 4; int userResponse; scanf ("%d", &userResponse); if (correctAnswer == userResponse) return 1; else return 0; }
// this is the question 5 int Question_5() { printf ("Where is Los Angeles? 1. California 2. San Diego 3. Nevada 4. Utah "); int correctAnswer = 1; int userResponse; scanf ("%d", &userResponse); if (correctAnswer == userResponse) return 1; else return 0; }
// this is the main function int main() { int score = 0; int x = Question_1(); if (x == 1) { printf ("Good job! "); score++; } else printf ("Sorry! your answer is wrong. ");
x = Question_2(); if (x == 1) { printf ("Good job! "); score++; } else printf ("Sorry! your answer is wrong. ");
x = Question_3(); if (x == 1) { printf ("Good job! "); score++; } else printf ("Sorry! your answer is wrong. ");
x = Question_4(); if (x == 1) { printf ("Good job! "); score++; } else printf ("Sorry! your answer is wrong. ");
x = Question_5(); if (x == 1) { printf ("Good job! "); score++; } else printf ("Sorry! your answer is wrong. ");
printf ("Total Points = 5 "); printf ("Your score = %d ", score); return 0; }
1. Extend the code
2. Ask the user, if he wants to practice or Take the real quiz. There are two modes of operation: Practice mode and QUIZ MODE.
3A. In the practice mode, the user is given three chances to provide the correct answer. Score is incremented only he answers correctly in those three chances. Otherwise, show him the correct answer and proceed.
3B. In the Quiz mode, there is no additional chances given. Score is incremented only if he answers correctly the first time.
4. The order of questions is random. use any method. The order of questions should be different each time you run.
[ submission : 5 points ]
HINT:
The function question_1 would be redefined as
int Question_1 ( int mode )
{
printf ( "What is the capital of USA ? 1. Atlanta 2. Washington DC 3. New York 4. Chicago " ) ;
int correctAnswer = 2 ;
int userResponse ;
if ( mode == TRAINING )
{ give him three chances.
}
else {
give him one chance
}
rewrite the rest of the functions
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
