/* Reena Rankawat  */

#include<iostream.h>
#include<conio.h>
void main(void)
{
    char name[50],ch[11];
    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[1];
        if(ch[1]=='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[2];
        if(ch[2]=='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[3];
        if(ch[3]=='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[4];
        if(ch[4]=='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[5];
        if(ch[5]=='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[6];
        if(ch[6]=='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[7];
        if(ch[7]=='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[8];
        if(ch[8]=='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[9];
        if(ch[9]=='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[10];
        if(ch[10]=='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[11];
    }
    while(ch[11]=='Y'||ch[11]=='y');
    getch();
}

Recommended Answers

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[3];
    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 developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.