``````/* Reena Rankawat  */

#include<iostream.h>
#include<conio.h>
void main(void)
{
char name,ch;
int x;
clrscr();
do
{
x=0;
cout<<"\n       Welcome to KBC";
cout<<"\n\n Enter your name: ";
cin>>name;
cout<<"\n Enter answer in form of 'a','b' and'c'only.";
cout<<"\n Q1.What is called as ' THE HOLY LAND'?";
cout<<"\n a.Jerusalem";
cout<<"\n b.Mathura";
cout<<"\n c.Mecca";
cin>>ch;
if(ch=='a')
{
x=x+10;
cout<<"\n Good Job.";
cout<<"\n Your score is "<<x;
}
else
{
cout<<"\n Sorry wrong answer.";
goto abc;
}
cout<<"\n Q2.What is called as ' THE ROOF OF THE WORLD'?";
cout<<"\n a.Nepal";
cout<<"\n b.Rome";
cout<<"\n c.Tibet";
cin>>ch;
if(ch=='c')
{
x=x+10;
cout<<"\n Good Job.";
cout<<"\n Your score is "<<x;
}
else
{
cout<<"\n Sorry wrong answer.";
goto abc;
}
cout<<"\n Q3.What is called as ' THE LAND OF RISING SUN'?";
cout<<"\n a.Chicago";
cout<<"\n b.Japan";
cout<<"\n c.Tibet";
cin>>ch;
if(ch=='b')
{
x=x+10;
cout<<"\n Good Job.";
cout<<"\n Your score is "<<x;
}
else
{
cout<<"\nSorry wrong answer.";
goto abc;
}
cout<<"\n Q4.What is called as ' THE GIFT OF NILE'?";
cout<<"\n a.Chicago";
cout<<"\n b.Egypt";
cout<<"\n c.Africa";
cin>>ch;
if(ch=='b')
{
x=x+10;
cout<<"\n Good Job.";
cout<<"\n Your score is "<<x;
}
else
{
cout<<"Sorry wrong answer.";
goto abc;
}
cout<<"\n Q5.What is called as ' THE LAND OF MIDNIGHT SUN'?";
cout<<"\n a.Norway";
cout<<"\n b.Japan";
cout<<"\n c.Australia";
cin>>ch;
if(ch=='a')
{
x=x+10;
cout<<"\n Good Job.";
cout<<"\n Your score is "<<x;
}
else
{
cout<<"\n Sorry wrong answer.";
goto abc;
}
cout<<"\n Q6.What is called as ' THE LAND OF THUNDERBOLT'?";
cout<<"\n a.Bhutan";
cout<<"\n b.Canada";
cout<<"\n c.Arab";
cin>>ch;
if(ch=='a')
{
x=x+10;
cout<<"\n Good Job.";
cout<<"\n Your score is "<<x;
}
else
{
cout<<"\n Sorry wrong answer.";
goto abc;
}
cout<<"\n Q7.What is called as ' THE WINDY CITY?";
cout<<"\n a.Jerusalem";
cout<<"\n b.Japan";
cout<<"\n c.Chicago";
cin>>ch;
if(ch=='c')
{
x=x+10;
cout<<"\n Good Job.";
cout<<"\n Your score is "<<x;
}
else
{
cout<<"\n Sorry wrong answer.";
goto abc;
}
cout<<"\n Q8.What is called as ' THE LAND OF WHITE ELEPHANTS'?";
cout<<"\n a.Bangladesh";
cout<<"\n b.Thailand";
cout<<"\n c.India";
cin>>ch;
if(ch=='b')
{
x=x+10;
cout<<"\n Good Job.";
cout<<"\n Your score is "<<x;
}
else
{
cout<<"\n Sorry wrong answer.";
goto abc;
}
cout<<"\n Q9.What is called as ' THE CITY OF SEVEN HILLS'?";
cout<<"\n a.Rome";
cout<<"\n b.Nilgiri Hills";
cout<<"\n c.Tibet";
cin>>ch;
if(ch=='a')
{
x=x+10;
cout<<"\n Good Job.";
cout<<"\n Your score is "<<x;
}
else
{
cout<<"\n Sorry wrong answer";
goto abc;
}
cout<<"\n Q10.What is called as ' THE DARK CONTIENENT'?";
cout<<"\n a.Asia";
cout<<"\n b.Australia";
cout<<"\n c.Africa";
cin>>ch;
if(ch=='c')
{
x=x+10;
cout<<"\n Good Job.";
cout<<"\n Your score is "<<x;
}
else
{
cout<<"\n Sorry wrong answer.";
goto abc;
}
abc:
if(x==100)
{
cout<<"\n No cheating...... "<<name<<" you have done this earlier also.";
break;
}
if(x==90)
{
cout<<"\n "<<name<<" you are extremely intelligent.";
cout<<"\n Your Score is 90";
}
if(x==80)
{
cout<<"\n "<<name<<" you are intelligent.";
cout<<"\n Your Score is 80";
}
if(50==x||x==70||x==60)
{
cout<<"\n "<<name<<" you are average";
cout<<"\n Your Score is "<<x<<".";
cout<<"\n Better luck next time";
}
else
if(x<=40)
cout<<"\n No use........ Not even 5 questions right";
cout<<"\n\n\n Do you want to play again?(y/n)";
cin>>ch;
}
while(ch=='Y'||ch=='y');
getch();
}
``````

## Recommended Answers

In the absence of the necesary information from the OP, I can only make broad suggestions, with the number one recommendation being to replace all of these repetitive tests with a table and simple loop.

``````struct Q_and_A
{
std::string question;
std::string options;
char answer;
int points;
}; …``````

## All 3 Replies

what is your question?

what is your question?

As if you read my mind.

Beside posting this long code, what seems to be the problem?
I see you use these:

``````#include<iostream.h>
#include<conio.h>
``````

There are some topics related to that of using conio.h.
And in C++ nowdays it's <iostream> not <iostream.h>

In the absence of the necesary information from the OP, I can only make broad suggestions, with the number one recommendation being to replace all of these repetitive tests with a table and simple loop.

``````struct Q_and_A
{
std::string question;
std::string options;
char answer;
int points;
};

Q_and_A exam[] = {
{"What is called 'THE HOLY LAND'?", {"Jerusalem", "Mathura", "Mecca"}, 'a', 10},
{"What is called 'THE ROOF OF THE WORLD'?", {"Nepal", "Rome", "Tibet"}, 'c', 10},
// and so on ...
{"What is called 'THE DARK CONTINENT'?", {"Asia", "Australia", "Africa"}, 'c', 10}
};

// later, in the program code...

for (int i = 0; i < 10; i++)
{
char answer;

std::cout << std::endl << "Q" << i <<". " << exam[i].question << std::endl;
for (int j = 0; j < 3; j++)
{
std::cout << ('a' + (char) j) << ". " << exam[i].option[j] << std::endl;
}
cin >> answer;
if (answer = exam[i].answer)
{
x += exam[i].points;
std::cout << "\nGood Job.";
std::cout<<"\n Your score is " << x << std::endl;
}
else
{
std::cout << "\n Sorry wrong answer." << std::endl;
}
}
``````

I don't know if this solves the problem you were posting about, but I'll bet it solves a lot more than just that.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.