# Thread: makig a Randomizes Quiz Help

1. ## makig a Randomizes Quiz Help

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.

Code:
```//Quiz program
#include <iostream>
#include <string>
#include <time.h>

using namespace std;

//Arrays and Variables and Strings
int Q = {};
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;

cout << "Ans. ";
cin >> Q;
cout << endl << endl;
//Question 1 Evaluation:
if (Q == 1)
{
cout << correct << endl << endl;
score = score + 1	;
}

else if (Q == 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;

cout << "Ans. ";
cin >> Q;
cout << endl << endl;
//Question 2 Evaluation:
if (Q == 2)
{
cout << correct << endl << endl;
score = score + 1;
}

else if (Q == 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;

cout << "Ans. ";
cin >> Q;
cout << endl << endl;
//Question 4 Evaluation:
if (Q == 1)
{
cout << correct << endl << endl;
score = score + 1;
}

else if (Q == 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;

cout << "Ans. ";
cin >> Q;
cout << endl << endl;
//Question 4 Evaluation:
if (Q == 1)
{
cout << correct << endl << endl;
score = score + 1;
}

else if (Q == 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;

cout << "Ans. ";
cin >> Q;
cout << endl << endl;
//Question 5 Evaluation:
if (Q == 2)
{
cout << correct << endl << endl;
score = score + 1;
}

else if (Q == 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;

cout << "Ans. ";
cin >> Q;
cout << endl << endl;
//Question 6 Evaluation:
if (Q == 1)
{
cout << correct << endl << endl;
score = score + 1;
}

else if (Q == 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;

cout << "Ans. ";
cin >> Q;
cout << endl << endl;
//Question 7 Evaluation:
if (Q == 1)
{
cout << correct << endl << endl;
score = score + 1;
}

else if (Q == 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;

cout << "Ans. ";
cin >> Q;
cout << endl << endl;

//Question 8 Evaluation:
if (Q == 1)
{
cout << correct << endl << endl;
score = score + 1;
}

else if (Q == 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;

cout << "Ans. ";
cin >> Q;
cout << endl << endl;
//Question 9 Evaluation:
if (Q == 3)
{
cout << correct << endl << endl;
score = score + 1;
}

else if (Q == 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;

cout << "Ans. ";
cin >> Q;
cout << endl << endl;
//Question 10 Evaluation:
if (Q == 4)
{
cout << correct << endl << endl;
score = score + 1;
}

else if (Q == 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 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. 2. You can start by making "question" a function or class so that you do not have to repeat it over and over. This will make it easy to select random questions from an array. 3. Could you elaborately explain it? And I haven't learnt using classes yet. 4. I studied Classes for a while and then tried to make the class question.

I used the following code:
Code:
```//Arrayrs, Variables and Strings
int x;
int q;
int w;
int e;
int r;
int t;
int y;
int u;
int i;
int o;
int p;
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 skip = "You skipped the Question";
string divider = "--------------------------------------------------------------------------------";

//Qestion Class
class Question
{
public:
Question ();
//Constructor
~Question ();
//Destructor

protected:
int a, b, c, d;

int number (int a);

string question (char);

string opt1 (char);

string opt2 (char);

string opt3 (char);

string opt4 (char);

int correct_ans (int c);
int  ans(int c)
{
if (b == c)
{
cout << correct;
score += 1;
}
else if ( b == 0 )
{
cout << skip;
}

else
{
cout << wrong;
score -=0.5;
}
};```
But after I try to compile it, I encounter "fatal error C1075: end of file found before the left brace '{' at ..............

I have made the bracket bold, the one mentioned in the error.

Please tell me what to do now, and How to use this class in my program. Popular pages Recent additions quiz, random 