I am trying to make a simple quiz program. Well I am just a beginner at it.
Here I have deigned a simple quiz that gives the user 10 question and depending on their answer respond to them.
I wanted to make the quiz random, like, I add 5 more questions to the list, and then the program choses any 10 of those 15 question and presents them to the user.Code://Quiz program #include <iostream> #include <string> #include <time.h> using namespace std; //Arrays and Variables and Strings int Q[10] = {}; float score = 0; string correct = "This is the correct answer"; string wrong = "Sorry, this is the incorrect answer. The correct answer was "; /*The correct option will have to be put after "<<"*/ string divider = "--------------------------------------------------------------------------------"; //Main Program int main () { //Timer Define int elapTicks; double elapMilli, elapSeconds, elapMinutes; clock_t Begin, End; //initialize Begin and End for the timer //Instructions: cout << "There will be 10 questions each having 4 options and ONLY 1 Correct answer." << endl; cout << "To select the answer, type the correct option number and press ENTER/RETURN." << endl; cout << "ONE MARK will be provided for a correct answer and HALF A MARK [0.5] will be deducted for a wrong one."<< endl; cout << "No marks will be deducted for skipping a Question." << endl << "A QUESTION CAN BE SKIPPED BY ENTERING THE OPTION NUMBER AS 0" << endl; cout << divider << endl << endl; //Timer Start Begin = clock() * CLK_TCK; for(int a=1; a<=10000; a++); //Questions: //Question 1 cout << "1) First China War was fought between ____________" << endl; cout << "1.China and Britain" << endl; cout << "2.China and France" << endl; cout << "3.China and Egypt" << endl; cout << "4.China and Russia" << endl << endl; //Question 1 Answer cout << "Ans. "; cin >> Q[0]; cout << endl << endl; //Question 1 Evaluation: if (Q[0] == 1) { cout << correct << endl << endl; score = score + 1 ; } else if (Q[0] == 0) cout << "You skipped the Question" << endl << endl; else { cout << wrong << "1. CHINA AND BRITAIN" << endl << endl; score = score - 0.5; } cout << divider << endl << endl; //Question 2: cout << "2)For the Olympics and World Tournaments, the dimensions of basketball court are____________" << endl; cout << "1.26 m x 14 m" << endl; cout << "2.28 m x 15 m" << endl; cout << "3.27 m x 16 m" << endl; cout << "4.28 m x 16 m" << endl << endl; //Question 2 Answer cout << "Ans. "; cin >> Q[1]; cout << endl << endl; //Question 2 Evaluation: if (Q[1] == 2) { cout << correct << endl << endl; score = score + 1; } else if (Q[1] == 0) cout << "You skipped the Question" << endl << endl; else { cout << wrong << "2. 2.28 m x 15 m" << endl << endl; score = score - 0.5; } cout << divider << endl << endl; //Question 3: cout << "3)Each year World Red Cross and Red Crescent Day is celebrated on" << endl; cout << "1.May 8" << endl; cout << "2.May 18" << endl; cout << "3.June 8" << endl; cout << "4.June 18" << endl << endl; //Question 3 Answer cout << "Ans. "; cin >> Q[2]; cout << endl << endl; //Question 4 Evaluation: if (Q[2] == 1) { cout << correct << endl << endl; score = score + 1; } else if (Q[2] == 0) cout << "You skipped the Question" << endl << endl; else { cout << wrong << "1. MAY 8" << endl << endl; score = score - 0.5; } cout << divider << endl << endl; //Question 4: cout << "4)Friction can be reduced by changing from____________" << endl; cout << "1.sliding to rolling" << endl; cout << "2.rolling to sliding" << endl; cout << "3.Kynetic to Dynamic" << endl; cout << "4.dynamic to static" << endl << endl; //Question 4 Answer cout << "Ans. "; cin >> Q[3]; cout << endl << endl; //Question 4 Evaluation: if (Q[3] == 1) { cout << correct << endl << endl; score = score + 1; } else if (Q[3] == 0) cout << "You skipped the Question" << endl << endl; else { cout << wrong << "1.SLIDING TO ROLLING" << endl << endl; score = score - 0.5; } cout << divider << endl << endl; //Question 5: cout << "5)Georgia, Uzbekistan and Turkmenistan became the members of UNO in_____" << endl; cout << "1.1991" << endl; cout << "2.1992" << endl; cout << "3.1993" << endl; cout << "4.1994" << endl << endl; //Question 5 Answer cout << "Ans. "; cin >> Q[4]; cout << endl << endl; //Question 5 Evaluation: if (Q[4] == 2) { cout << correct << endl << endl; score = score + 1; } else if (Q[4] == 0) cout << "You skipped the Question" << endl << endl; else { cout << wrong << "2.1992" << endl << endl; score = score - 0.5; } cout << divider << endl << endl; //Question 6: cout << "6)During World War II, when did Germany attack France?" << endl; cout << "1.1940" << endl; cout << "2.1941" << endl; cout << "3.1942" << endl; cout << "4.1993" << endl << endl; //Question 6 Answer cout << "Ans. "; cin >> Q[5]; cout << endl << endl; //Question 6 Evaluation: if (Q[5] == 1) { cout << correct << endl << endl; score = score + 1; } else if (Q[5] == 0) cout << "You skipped the Question" << endl << endl; else { cout << wrong << "2.1940" << endl << endl; score = score - 0.5; } cout << divider << endl << endl; //Question 7: cout << "7)Frederick Sanger is a twice recipient of the Nobel Prize for ______" << endl; cout << "1.Chemistry in 1958 and 1980" << endl; cout << "2.Physics in 1956 and 1972" << endl; cout << "3.Chemistry in 1954 and Peace in 1962" << endl; cout << "4.Physics in 1903 and Chemistry in 1911" << endl << endl; //Question 7 Answer cout << "Ans. "; cin >> Q[6]; cout << endl << endl; //Question 7 Evaluation: if (Q[6] == 1) { cout << correct << endl << endl; score = score + 1; } else if (Q[6] == 0) cout << "You skipped the Question" << endl << endl; else { cout << wrong << "1.CHEMISTRY IN 1958 AND 1980" << endl << endl; score = score - 0.5; } cout << divider << endl << endl; //Question 8: cout << "8)Eugenics is the study of" << endl; cout << "1.altering human beings by changing their genetic components" << endl; cout << "2.people of European origin" << endl; cout << "3.different races of mankind" << endl; cout << "4.genetic of plants" << endl << endl; //Question 8 Answer cout << "Ans. "; cin >> Q[7]; cout << endl << endl; //Question 8 Evaluation: if (Q[7] == 1) { cout << correct << endl << endl; score = score + 1; } else if (Q[7] == 0) cout << "You skipped the Question" << endl << endl; else { cout << wrong << "1.ALTERING HUMAN BEINGS BY CHANGING THEIR GENETIC COMPONENTS" << endl << endl; score = score - 0.5; } cout << divider << endl << endl; //Question 9: cout << "9)Goa Shipyard Limited (GSL) was established in ____" << endl; cout << "1.1955" << endl; cout << "2.1956" << endl; cout << "3.1957" << endl; cout << "4.1958" << endl << endl; //Question 9 Answer cout << "Ans. "; cin >> Q[8]; cout << endl << endl; //Question 9 Evaluation: if (Q[8] == 3) { cout << correct << endl << endl; score = score + 1; } else if (Q[8] == 0) cout << "You skipped the Question" << endl << endl; else { cout << wrong << "3.1957" << endl << endl; score = score - 0.5; } cout << divider << endl << endl; //Question 10: cout << "10)Escape velocity of a rocket fired from the earth towards the moon is a velocity to get rid of the _______" << endl; cout << "1.Pressure of the atmosphere" << endl; cout << "2.Moon's gravitational pull" << endl; cout << "3.Centripetal force due to the earth's rotation" << endl; cout << "4.Earth's gravitational pull" << endl << endl; //Question 10 Answer cout << "Ans. "; cin >> Q[9]; cout << endl << endl; //Question 10 Evaluation: if (Q[9] == 4) { cout << correct << endl << endl; score = score + 1; } else if (Q[9] == 0) cout << "You skipped the Question" << endl << endl; else { cout << wrong << "4.EARTH'S GRAVITATIONAL PULL" << endl << endl; score = score - 0.5; } //Timer stop: End = clock() * CLK_TCK; //stop the timer //Thanks Note: cout << "---------------------------------Test Completed---------------------------------" << endl << endl; //Scoring: cout << "Your total score was " << score << " points!" << endl; //Time Taken: elapTicks = End - Begin; //the number of ticks from Begin to End elapMilli = elapTicks/1000; //milliseconds from Begin to End elapSeconds = elapMilli/1000; //seconds from Begin to End elapMinutes = elapSeconds/60; //minutes from Begin to End if(elapSeconds < 1) cout<<"\n\nYou took "<<elapMilli<<" milliseconds."; else if(elapSeconds == 1) cout<<"\n\nYou took 1 second."; else if(elapSeconds > 1 && elapSeconds < 60) cout<<"\n\nYou took "<<elapSeconds<<" seconds."; else if(elapSeconds >= 60) cout<<"\n\nYou took "<<elapMinutes<<" minutes."; //Terminating the Program: return 0; }
I am using Visual C++ in windows. Can some one please help me?
Thanks in advance.



LinkBack URL
About LinkBacks


