Hi! I need help to my c++ program. I created a program that is much like the "Who wants to be a Millionaire" television show. It has questions and the right answers and three lifelines. How can I possibly do eliminate a lifeline after being used.?

this is the program I created so far:

#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
void box(int x, int xx, int y, int yy);
void box(int x, int xx, int y, int yy)
{
int xs,ys,i,j;
xs=xx-x;
ys=yy-y;
for(i=1; i<xs; i++){gotoxy(x+i,y);cout<<"Í";
		    gotoxy(x+i,yy);cout<<"Í"; }
for(j=1; j<ys; j++){gotoxy(x,y+j);cout<<"º"; }
for(j=1; j<ys; j++){gotoxy(xx,y+j);cout<<"º"; }
		   {gotoxy(x,y);cout<<"É";
		    gotoxy(x,yy);cout<<"È";
		    gotoxy(xx,y);cout<<"»";
		    gotoxy(xx,yy);cout<<"¼";}
}
char name[50];
char ans;
char ask;
int life;
int main()
{
clrscr();
box(20,50,9,15);
gotoxy(22,12);cout<<"Your Name: ";
cin>>name;
getch();
clrscr();
box(5,50,9,50);
box(10,65,1,5);
gotoxy(23,3);cout<<"Who Wants to be a MILLIONAIRE?";
box(55,78,8,30);
gotoxy(62,12);cout<<"LIFELINE";
gotoxy(57,15);cout<<"1. 50:50";

gotoxy(57,18);cout<<"2. Call a friend";
gotoxy(57,21);cout<<"3. Ask the audience";

gotoxy(6,10);cout<<"QUESTION 1:";
gotoxy(12,13);cout<<"Who discovered Computer?";
gotoxy(8,15);cout<<"a. Charles Darwin";
gotoxy(29,15);cout<<"b. Charles Babbage";
gotoxy(8,17);cout<<"c. Isaac Newton";
gotoxy(29,17);cout<<"d. Abraham Lincoln";
getch();
gotoxy(9,22);cout<<"Do you want to use your lifeline?";
gotoxy(13,24);cout<<"[ Y/N : ]  ";
cin>>ask;
if(ask=='y')
{
gotoxy(10,28);cout<<"Choose Lifeline Number:  ";
cin>>life;
if(life==1)
{
gotoxy(18,31);cout<<"[ 50:50 ]";
gotoxy(8,34);cout<<"_________";
gotoxy(29,34);cout<<"c. Isaac Newton";
gotoxy(8,37);cout<<"b. Charles Babbage";
gotoxy(29,37);cout<<"_________";
getch();
}
else if(life==2)
{
gotoxy(18,31);cout<<"[ Call a friend ]";
gotoxy(10,34);cout<<"Friend: I think it is B";
getch();
gotoxy(10,36);cout<<"You: How sure are you?";
getch();
gotoxy(10,38);cout<<"Friend: I'm 95% sure about this.";
getch();
}
else if(life==3)
{
gotoxy(18,31);cout<<"[ Ask the audience ]";
gotoxy(8,36);cout<<"(a.) 23%   (b.) 52%   (c.) 13%   (d.) 12%";
getch();
}
}
else if(ask=='n')
getch();
gotoxy(16,42);cout<<"Your answer is: ";
cin>>ans;
if(ans=='b')
{
gotoxy(18,45);cout<<"You're Right!";
getch();
gotoxy(16,47);cout<<"You just won $20,000!!!";
getch();
gotoxy(15,49);cout<<"Get ready for the next round!";
}
else
{
gotoxy(18,45);cout<<"Wrong!";
gotoxy(16,47);cout<<"Try again";
getch();
exit(0);
}
getch();




clrscr();
box(5,50,9,50);
box(10,65,1,5);
gotoxy(23,3);cout<<"Who Wants to be a MILLIONAIRE?";
box(55,78,8,30);
gotoxy(62,12);cout<<"LIFELINE";
gotoxy(57,15);cout<<"1.  50:50";
gotoxy(57,18);cout<<"2.  Call a friend";
gotoxy(57,21);cout<<"3.  Ask the audience";
gotoxy(6,10);cout<<"QUESTION 2:";
gotoxy(10,13);cout<<"Folder contains...?";
gotoxy(10,15);cout<<"a. Foods";
gotoxy(28,15);cout<<"b. Animals";
gotoxy(10,17);cout<<"c. Clothes";
gotoxy(28,17);cout<<"d. Files";
getch();
gotoxy(9,22);cout<<"Do you want to use your lifeline?";
gotoxy(13,24);cout<<"[ Y/N : ]  ";
cin>>ask;
if(ask=='y')
{
gotoxy(10,28);cout<<"Choose Lifeline Number:  ";
cin>>life;
if(life==1)
{
gotoxy(18,31);cout<<"[ 50:50 ]";
gotoxy(10,34);cout<<"a. Foods";
gotoxy(26,34);cout<<" _________";
gotoxy(10,37);cout<<" _________";
gotoxy(26,37);cout<<"d. Files";
getch();
}
else if(life==2)
{
gotoxy(18,31);cout<<"[ Call a friend ]";
gotoxy(10,34);cout<<"Friend: I think it is D";
getch();
gotoxy(10,36);cout<<"You: How sure are you?";
getch();
gotoxy(10,38);cout<<"Friend: I'm 95% sure about this.";
getch();
}
else if(life==3)
{
gotoxy(18,31);cout<<"[ Ask the audience ]";
gotoxy(8,36);cout<<"(a.) 23%   (b.) 12%   (c.) 13%   (d.) 52%";
getch();
}
}
else if(ask=='n')
getch();
gotoxy(16,42);cout<<"Your answer is: ";
cin>>ans;
if(ans=='d')
{
gotoxy(18,45);cout<<"You're Right!";
getch();
gotoxy(16,47);cout<<"You just won $50,000!!!";
getch();
gotoxy(15,49);cout<<"Get ready for the next round!";
}

else
{
gotoxy(18,45);cout<<"Wrong!";
gotoxy(16,47);cout<<"Try again";
getch();
exit(0);
}
getch();




{
clrscr();
box(5,50,9,50);
box(10,65,1,5);
gotoxy(23,3);cout<<"Who Wants to be a MILLIONAIRE?";
box(55,78,8,30);
gotoxy(62,12);cout<<"LIFELINE";
gotoxy(57,15);cout<<"1.  50:50";
gotoxy(57,18);cout<<"2.  Call a friend";
gotoxy(57,21);cout<<"3.  Ask the audience";
gotoxy(6,10);cout<<"QUESTION 3:";
gotoxy(10,12);cout<<"What is the brain of the computer?";
gotoxy(10,15);cout<<"a. Keyboard";
gotoxy(28,15);cout<<"b. Printer";
gotoxy(10,17);cout<<"c. CPU";
gotoxy(28,17);cout<<"d. Monitor";
getch();
gotoxy(9,22);cout<<"Do you want to use your lifeline?";
gotoxy(13,24);cout<<"[ Y/N : ]  ";
cin>>ask;
if(ask=='y')
{
gotoxy(10,28);cout<<"Choose Lifeline Number:  ";
cin>>life;
if(life==1)
{
gotoxy(18,31);cout<<"[ 50:50 ]";
gotoxy(10,34);cout<<"a. Foods";
gotoxy(26,34);cout<<"b. _________";
gotoxy(10,37);cout<<"c. CPU";
gotoxy(26,37);cout<<"d. _________";
getch();
}
else if(life==2)
{
gotoxy(18,31);cout<<"[ Call a friend ]";
gotoxy(10,34);cout<<"Friend: I think it is C";
getch();
gotoxy(10,36);cout<<"You: How sure are you?";
getch();
gotoxy(10,38);cout<<"Friend: I'm 87% sure about this.";
getch();
}
else if(life==3)
{
gotoxy(18,31);cout<<"[ Ask the audience ]";
gotoxy(8,36);cout<<"(a.) 23%   (b.) 12%   (c.) 53%   (d.) 12%";
getch();
}
}
else if(ask=='n')
getch();
gotoxy(16,42);cout<<"Your answer is: ";
cin>>ans;
if(ans=='c')
{
gotoxy(18,45);cout<<"You're Right!";
getch();
gotoxy(16,47);cout<<"You just won $200,000!!!";
getch();
gotoxy(15,49);cout<<"Get ready for the next round!";
}

else
{
gotoxy(18,45);cout<<"Wrong!";
gotoxy(16,47);cout<<"Try again";
getch();
exit(0);
}
getch();




{
clrscr();
box(5,50,9,50);
box(10,65,1,5);
gotoxy(23,3);cout<<"Who Wants to be a MILLIONAIRE?";
box(55,78,8,30);
gotoxy(62,12);cout<<"LIFELINE";
gotoxy(57,15);cout<<"1.  50:50";
gotoxy(57,18);cout<<"2.  Call a friend";
gotoxy(57,21);cout<<"3.  Ask the audience";
gotoxy(6,10);cout<<"QUESTION 4:";
gotoxy(8,12);cout<<"Set of instructions for a computer to do?";
gotoxy(10,15);cout<<"a. Computer Program";
gotoxy(33,15);cout<<"b. Photoshop";
gotoxy(10,17);cout<<"c. DreamWeaver";
gotoxy(33,17);cout<<"d. Autocad";
getch();
gotoxy(9,22);cout<<"Do you want to use your lifeline?";
gotoxy(13,24);cout<<"[ Y/N : ]  ";
cin>>ask;
if(ask=='y')
{
gotoxy(10,28);cout<<"Choose Lifeline Number:  ";
cin>>life;
if(life==1)
{
gotoxy(18,31);cout<<"[ 50:50 ]";
gotoxy(10,34);cout<<"a. Computer Program";
gotoxy(33,34);cout<<"b. Photoshop";
gotoxy(10,37);cout<<" _________";
gotoxy(33,37);cout<<"_________";
getch();
}
else if(life==2)
{
gotoxy(18,31);cout<<"[ Call a friend ]";
gotoxy(10,34);cout<<"Friend: I think it is A";
getch();
gotoxy(10,36);cout<<"You: How sure are you?";
getch();
gotoxy(10,38);cout<<"Friend: I'm 58% sure about this.";
getch();
}
else if(life==3)
{
gotoxy(18,31);cout<<"[ Ask the audience ]";
gotoxy(8,36);cout<<"(a.) 53%   (b.) 12%   (c.) 23%   (d.) 12%";
getch();
}
}
else if(ask=='n')
getch();
gotoxy(16,42);cout<<"Your answer is: ";
cin>>ans;
if(ans=='a')
{
gotoxy(18,45);cout<<"You're Right!";
getch();
gotoxy(16,47);cout<<"You just won $500,000!!!";
getch();
gotoxy(15,49);cout<<"Get ready for the next round!";
}

else
{
gotoxy(18,45);cout<<"Wrong!";
gotoxy(16,47);cout<<"Try again";
getch();
exit(0);
}
getch();





{
clrscr();
box(5,50,9,50);
box(10,65,1,5);
gotoxy(23,3);cout<<"Who Wants to be a MILLIONAIRE?";
box(55,78,8,30);
gotoxy(62,12);cout<<"LIFELINE";
gotoxy(57,15);cout<<"1.  50:50";
gotoxy(57,18);cout<<"2.  Call a friend";
gotoxy(57,21);cout<<"3.  Ask the audience";
gotoxy(6,10);cout<<"QUESTION 5:";
gotoxy(8,12);cout<<"Is a set of instructions to solve";
gotoxy(8,13);cout<<"a programming problem?";
gotoxy(10,15);cout<<"a. Math";
gotoxy(33,15);cout<<"b. Algorithm";
gotoxy(10,17);cout<<"c. Physics";
gotoxy(33,17);cout<<"d. Literature";
getch();
gotoxy(9,22);cout<<"Do you want to use your lifeline?";
gotoxy(13,24);cout<<"[ Y/N : ]  ";
cin>>ask;
if(ask=='y')
{
gotoxy(10,28);cout<<"Choose Lifeline Number:  ";
cin>>life;
if(life==1)
{
gotoxy(18,31);cout<<"[ 50:50 ]";
gotoxy(10,34);cout<<"_________";
gotoxy(30,34);cout<<"b. Algorithm";
gotoxy(10,37);cout<<"c. Physics";
gotoxy(30,37);cout<<"_________";
getch();
}
else if(life==2)
{
gotoxy(18,31);cout<<"[ Call a friend ]";
gotoxy(10,34);cout<<"Friend: I think it is B";
getch();
gotoxy(10,36);cout<<"You: How sure are you?";
getch();
gotoxy(10,38);cout<<"Friend: I'm 78% sure about this.";
getch();
}
else if(life==3)
{
gotoxy(18,31);cout<<"[ Ask the audience ]";
gotoxy(8,36);cout<<"(a.) 13%   (b.) 52%   (c.) 23%   (d.) 12%";
getch();
}
}
else if(ask=='n')
getch();
gotoxy(16,42);cout<<"Your answer is: ";
cin>>ans;
if(ans=='b')
{
gotoxy(18,45);cout<<"You're Right!";
getch();
gotoxy(16,47);cout<<"You won $1,000,000!!!";
getch();
gotoxy(18,49);cout<<"Congratulations!!!";
getch();
clrscr();
box(10,70,10,15);
gotoxy(12,13);cout<<"Congratulations to our new MILLIONAIRE: "<<name;
}

else
{
gotoxy(18,45);cout<<"Wrong!";
gotoxy(16,47);cout<<"Try again";
getch();
exit(0);
}
getch();
}}}}

Dani AI

Generated

Refactor the lifeline logic into a small, reusable component and call it from a single question routine. That implements ’s suggestion to extract common code and uses ’s idea of a simple collection for lifelines. Keeping lifeline state separate makes it trivial to “eliminate” a lifeline: mark it used once and refuse further selection.

A minimal design:

  • A LifelineManager that holds availability for the three lifelines and exposes isAvailable(id) and use(id).
  • A single presentQuestion(...) function that takes the question text, the options, the correct index, and a reference to the LifelineManager. It handles showing options, asking about lifelines, validating selection with LifelineManager, applying the chosen lifeline effect, and returning whether the answer was correct.

Example (portable modern C++ sketch):

struct LifelineManager {
    std::array<bool,3> available{{true,true,true}};
    bool use(int id) {
        if (id<0 || id>=3) return false;
        if (!available[id]) return false;
        available[id]=false;
        return true;
    }
    bool isAvailable(int id) const {
        return id>=0 && id<3 && available[id];
    }
};

bool presentQuestion(const std::string& q,
                     const std::array<std::string,4>& opts,
                     int correctIndex,
                     LifelineManager& lm);

Implementation notes: for 50:50 build a list of wrong indices and hide two of them (random or deterministic). For “call a friend” return a suggested index and confidence. For “ask the audience” generate percentage hints. Always check isAvailable before use and update the on-screen lifeline display after use. Prefer standard C++ I/O (std::cout, std::getline, std::string, std::vector) instead of compiler-specific headers so the program compiles on modern compilers and the lifeline state persists correctly across questions.

Recommended Answers

All 4 Replies

before trying to implement eliminating lifelines I think you code is in desperate need to refactoring to put common code in functions that can be called.

For example:

A function that asks the question
Parameters:
The question
The 4 answers
The right answer
Returns a flag indicating if the question was answered correctly

A function that asks for a lifelline number
No parameters
Returns the number of a valid and available lifeline

In addition to what Banfa said, you need to learn formatting. Your code is completely unreadable. You should not ask someone else to try and help you with code that cannot be followed.

As for lifelines, you need to keep track of all three individually. Use an array.

before trying to implement eliminating lifelines I think you code is in desperate need to refactoring to put common code in functions that can be called.

For example:

A function that asks the question
Parameters:
The question
The 4 answers
The right answer
Returns a flag indicating if the question was answered correctly

A function that asks for a lifelline number
No parameters
Returns the number of a valid and available lifeline

------------------------------------------------------------------------------

Thanks for the reply! I really don't have any idea what "Parameters" you are talking about, I'm only just a beginner and what my teacher teach is only the basic. We haven't reach that too far. (^_^) I'll try to google it on my own. Thanks! and I'll be glad if you could still help figuring these things out for me. lol. Thanks again.

... what my teacher teach is only the basic.

No, what your teacher teaches is completely non-standard C that cannot be used in today's industry. TurboC++ is over 17 years old and is so outdated at least 3/4ths of your code cannot possibly be compiled on any current compiler. TurboC 3 I assume? Makes it almost 20 years old.

I hope you aren't paying a lot for your C++ class. You are getting ripped off.

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.