Thread: Multiple Choice Program(Who Wants To Be A Millionaire) Please Help!

  1. #1
    Registered User
    Join Date
    May 2012
    Posts
    1

    Unhappy Multiple Choice Program(Who Wants To Be A Millionaire) Please Help!

    Hi. I am New in this forum and i am also new to c++... Guys i am having problem in setting the high score.. i want my high score to be set after the user got a wrong answer. but in my program. the high score option always come after every question. please help. sorry for my english.

    Solution.H
    Code:
    #include "stdafx.h"
    #include <iostream>
    #include <iomanip>
    #include <string>
    #include <fstream>
    using namespace std;
    
    
    string ppplay, HighScoreName[10];
    int score=0,tscore=0, HighScore[10], Rank, coans;
    char aaaa;
    class game
    {
        
    public:
    
    
    
    
    
    
    int plays(int ques, string question, string option1, string option2, string option3, string option4, int correctAnswer)
    {
           
    system("cls");
    // Initialize a high score at 0
           HighScore[10] = 0;
         
           // Input the high scores from a file
           ifstream InputHighScores;
           InputHighScores.open ("HighScores.txt");
           while(!InputHighScores.eof())
           {
           int i = 0;
              InputHighScores >> HighScore[i];
              InputHighScores >> HighScoreName[i];
    
    
    
    
           }
    cout<<"++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ "<<endl;
    cout<<"+                                                                  + "<<endl;
    cout<<"+-------------------Who Wants To Be A Millionaire------------------+ "<<endl;
    cout<<"+                                                                  + "<<endl;
    cout<<"+                                                                  + "<<endl;
    cout<<"+--------------------------Programmed By---------------------------+ "<<endl;
    cout<<"+                                                                  + "<<endl;
    cout<<"+                          Ankit Chutani                           + "<<endl;
    cout<<"+                        Aldrin John Quebec                        + "<<endl;
    cout<<"+                   Gianpaolo D'jalma Villagracia                  + "<<endl;
    cout<<"+                                                                  + "<<endl;
    cout<<"++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ "<<endl<<endl;
    
    
        cout << "Question " << ques << "\t\t\t\t\t\t" << "YOU WON: $" << tscore << endl << endl; // question number and score
        cout <<  question  << endl;// question
        cout  << "1. " << option1  <<"\t\t\t" << "2. " << option2  << endl;  // four
        cout  << "3. " << option3  <<"\t\t\t" << "4. " << option4  << endl;  //options 
        char answer;
        cout << "Choose Your Answer: ";
        cin >> answer;
        if(answer!='1'&& answer!='2' && answer!='3' && answer!='4')
        {
            cout << "Wrong Input! Please Choose From Options Given Above: " ;
            cin >> answer;
        }
    
    
        
            while(answer != correctAnswer)
        {
            cout << endl;
            cout << "Sorry You Answered Wrong! You Lose!" << endl;
            cout << "You Have Won A Total Of: $" << tscore << endl << "Thanks For Playing!"<<endl;
            system("pause");
            exit(1);
            
        }
    
    
        if (tscore >= HighScore[10])
           {
              //Get user's rank
              for (int i = 10; tscore >= HighScore[i] && i >= 0; i--)
              {
                 Rank = i;
              }
         
              //Rearrange the high scores list
         
              for (int i = 10; i != Rank; i--)
              {
                 HighScore[i] = HighScore[i-1];
                 HighScoreName[i] = HighScoreName[i-1];
              }
         
              cout << "You got a high score!" << endl;
              cout << "Please enter your name." << endl;
              cin >> HighScoreName[Rank];
              HighScore[Rank] = tscore;
           }
        // Output the high scores to a file
           ofstream Output_High_Scores;
           Output_High_Scores.open ("HighScores.txt");
           for (int i = 0; i< 10; i++)
           {
              Output_High_Scores << HighScore[i] << endl;
              Output_High_Scores << HighScoreName[i] << endl;
           }
           Output_High_Scores.close ( );
    
    
    
    
    
    
        
        
        switch ( ques ) 
        {
            case 1:
            case 2:
            case 3:
            case 4:
            case 5:
            case 6:
            case 7:
            case 8:
            case 9:
            case 10:
            case 11:    
            case 12:
            case 13:
            case 14:
            case 15:
            case 16:
            case 17:
            case 18:
            case 19:
            case 20:
            case 21:
            case 22:
            case 23:
            case 24:
            case 25:
            case 26:
            case 27:
            case 28:
            case 29:
            case 30:
            case 31:
            case 32:
            case 33:
            case 34:
            case 35:
            case 36:
            case 37:
            case 38:
            case 39:
            case 40:
                tscore+=25000;
                score=25000;
                break;
            default:
                tscore=0;
                score = 0;
        }
        // special output for million dollar question
        if(ques == 40)
        {
            cout << "\nThats The Right Answer!!!\n"<< "Congratulations! You Are A Millionaire! \n Thanks for playing!"; 
            cin >> score;
            cin.get();
            exit (1);
        }
            //regular ouput for rest of the questions
        cout << "congrats you have answered right" << endl;
        cout << "you won : $" << score << endl << endl;
        char next;
        cout << "\npress y to play next question or\nyou can quit now by pressing q and take home " << score << " : " ;
        cin >> next;
        if(next != 'y'&& next != 'q')
        {
            cout << "wrong input type again: " ;
            cin >> next;
        }
        if(next == 'q')
        {
            cout << "\nyou have won total of " << score << "\nThank you for playing WWTBAM, bye" << endl;
            cin >> score;
            cin.get();
            exit (1);
        }
                    
    }
    
    
    
    
    };


    Output.H

    Code:
    #include "stdafx.h"#include <iostream>
    #include <iomanip>
    #include <string>
    #include <fstream>
    #include"Solution.h"
    using namespace std;
    
    
    
    
    class output : public game
    {
    protected:
        int option1;
        string head,playss,instructions,aboutgame, ch;
        char ready;
    public:
    
    
        void print()
        {
    
    
    
    
    main:
    system("cls");
    cout<<"++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ "<<endl;
    cout<<"+                                                                  + "<<endl;
    cout<<"+-------------------Who Wants To Be A Millionaire------------------+ "<<endl;
    cout<<"+                                                                  + "<<endl;
    cout<<"+                                                                  + "<<endl;
    cout<<"+--------------------------Programmed By---------------------------+ "<<endl;
    cout<<"+                                                                  + "<<endl;
    cout<<"+                          Ankit Chutani                           + "<<endl;
    cout<<"+                        Aldrin John Quebec                        + "<<endl;
    cout<<"+                   Gianpaolo D'jalma Villagracia                  + "<<endl;
    cout<<"+                                                                  + "<<endl;
    cout<<"++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ "<<endl<<endl<<endl;
    
    
    cout<<"**************************Choose An Option**************************"<<endl;
    cout<<"[1] Play Game"<<endl;
    cout<<"[2] Instructions"<<endl;
    cout<<"[3] About Game"<<endl;
    cout<<"[4] Exit"<<endl<<endl;
    cout<<"Enter Your Option:";
    cin>>option1;
    
    
    switch(option1)
    {
    case 1:
        goto playss;
        break;
    case 2:
        goto instructions;
        break;
    case 3:
        goto aboutgame;
        break;
    case 4:
        exit(0);
        break;
    
    
    
    
        }//sa switch option1
        
    playss:
        {
    system("cls");
    cout<<"++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ "<<endl;
    cout<<"+                                                                  + "<<endl;
    cout<<"+-------------------Who Wants To Be A Millionaire------------------+ "<<endl;
    cout<<"+                                                                  + "<<endl;
    cout<<"+                                                                  + "<<endl;
    cout<<"+--------------------------Programmed By---------------------------+ "<<endl;
    cout<<"+                                                                  + "<<endl;
    cout<<"+                          Ankit Chutani                           + "<<endl;
    cout<<"+                        Aldrin John Quebec                        + "<<endl;
    cout<<"+                   Gianpaolo D'jalma Villagracia                  + "<<endl;
    cout<<"+                                                                  + "<<endl;
    cout<<"++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ "<<endl<<endl<<endl;
        cout << "Are You Ready To Play?" << endl << "Press 'Y' To Start: ";
        cin >> ready;
        if (ready != 'y'&& ready!='Y')
        {
            cout << "wrong input press y to start \n";
            cin >> ready;
        }
        
        plays(
                1,                                                // question number
                "who is the first person to step on the moon?",    // name of the question
                "Bret 'HITMAN' hart",                            // option A
                "Alexander the Great",                            // option B
                "Neil Armstrong   ",                            // option C
                "Koffi Aanon",                                    // option D
                '3'                                                // Right option
            );
        plays(
                2,
                "what is the capital of holland?",
                "Luxemburg",
                "Amsterdam",
                "Munich   ",
                "Budapest",
                '2'
            );
        plays(
                3,
                "Which legal document states a person's wishes regarding the disposal of their property after death?",
                "wish ",
                "will",
                "shall",
                "screw you",
                '2'
            );
        plays(
                4,
                "Which of these sports does not involve playing with the ball?",
                "Football",
                "VolleyBall",
                "Archery ",
                "Getting laid",
                '3'
            );
        plays(
                5,
                "George Bush was the president of which country?",
                "Afghanistan",
                "Iraq",
                "Pakistan   ",
                "USA",
                '4'
            );
        plays(
                6,
                "Who won the footbal world cup in 2006?",
                "India",
                "Iran",
                "Iraq ",
                "Italy",
                '4'
            );
        plays(
                7,
                "William Shakespeare was ...",
                "Cheer leader",
                "poet",
                "Singer      ",
                "was the reason i failed in english class ",
                '2'
            );
        plays(
                8,
                "Who is the king of the jungle?",
                "Zebra ",
                "Lion",
                "Spider",
                "Snake",
                '2'
            );
        plays(
                9,
                "what is the capital of New Zealand",
                "Welligton",
                "Washington",
                "Auckland ",
                "Victoria",
                '1'
            );
        plays(
                10,
                "What is the company Super Mario official Masscot of?",
                "sega",
                "Microsoft",
                "sony",
                "nintendo",
                '4'
            );
        plays(
                11,
                "In the cartoon show Tom&Jerry, Tom is a ...",
                "Dog  ",
                "Cat",
                "Human",
                "Elepant",
                '2'
            );
        plays(
                12,
                "How many faces does a tradional Die has",
                "Two   ",
                "Six",
                "Twelve",
                "Four",
                '2'
            );
        plays(
                13,
                "According to common saying what will set you free ?",
                "Guilt",
                "Ego",
                "Truth",
                "........",
                '3'
            );
        plays(
                14,
                "What is name of the main character in the game GTA VICE CITY?",
                "Nico ",
                "Tommy Vercetti",
                "Roman",
                "CJ",
                '2'
            );
        plays(
                15,
                "How many zeros are there in a million",
                "Five ",
                "Six",
                "Seven",
                "Eight",
                '2'
            );
    
    
    
    
    
    
    
    
         
           // Print the high score list
           cout << "High Score List" << endl;
           cout << endl;
           for (int i = 0; i< 10; i++)
           {
              cout << HighScore[i] << " " << HighScoreName[i] << endl;
           }
         
           
    
    
    
    
    
    
    
    
        }//sa play:
    
    
    
    
    
    
    instructions:
        {
    system("cls");
    cout<<"++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ "<<endl;
    cout<<"+                                                                  + "<<endl;
    cout<<"+-------------------Who Wants To Be A Millionaire------------------+ "<<endl;
    cout<<"+                                                                  + "<<endl;
    cout<<"+                                                                  + "<<endl;
    cout<<"+--------------------------Programmed By---------------------------+ "<<endl;
    cout<<"+                                                                  + "<<endl;
    cout<<"+                          Ankit Chutani                           + "<<endl;
    cout<<"+                        Aldrin John Quebec                        + "<<endl;
    cout<<"+                   Gianpaolo D'jalma Villagracia                  + "<<endl;
    cout<<"+                                                                  + "<<endl;
    cout<<"++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ "<<endl<<endl<<endl;
    
    
    
    
        }//sa instructions:
    
    
    
    
    aboutgame:
        {
    system("cls");
    cout<<"++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ "<<endl;
    cout<<"+                                                                  + "<<endl;
    cout<<"+-------------------Who Wants To Be A Millionaire------------------+ "<<endl;
    cout<<"+                                                                  + "<<endl;
    cout<<"+                                                                  + "<<endl;
    cout<<"+--------------------------Programmed By---------------------------+ "<<endl;
    cout<<"+                                                                  + "<<endl;
    cout<<"+                          Ankit Chutani                           + "<<endl;
    cout<<"+                        Aldrin John Quebec                        + "<<endl;
    cout<<"+                   Gianpaolo D'jalma Villagracia                  + "<<endl;
    cout<<"+                                                                  + "<<endl;
    cout<<"++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ "<<endl<<endl<<endl;
    cout<<"*****************************About Game*****************************"<<endl;
    cout<<"This Program Is Our Final Project For Computer Programming 2."<<endl<<endl;
    cout<<"Programmed by:"<<endl;
    cout<<"Ankit Chutani"<<endl;
    cout<<"Aldrin John Quebec"<<endl;
    cout<<"Gianpaolo D'jalma Villagracia"<<endl;
    cout<<"In This Program We Used Inheritance And File Processing."<<endl<<endl;
    cout<<"Copyright 2012-2013 ComputerProgramming2, All Rights Reserved."<<endl<<endl;
    cout<<"Do You Want To Go Back To Main Menu (Y/N)?";
    cin>>ch;
    if (ch=="y" || ch=="Y")
    {
    goto main;
    }
    else
    {
    exit(0);
    }
    
    
    
    
    
    
    
    
    
    
        }//sa aboutgame:
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
        
    }//print()
    
    
    
    
    
    
    
    
    };//closing of class


    Main.CPP

    Code:
    #include"stdafx.h"
    #include <iostream>
    #include <string>
    #include <iomanip>
    #include <fstream>
    #include"Output.h"
    using namespace std;
    
    
    int main(int argc, char *argv[]) {
    
    
        output a;
        a.print();
        system("pause");
        return 0;
    }





    This is my project.. but i'm totally confused... i have to use the inheritance and file input/output... please help me... can you fix the code?... pleasehelp..
    Last edited by SmïLëÿboÿ Ako; 05-20-2012 at 12:43 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help Needed Fast! Multiple Choice Grading Program
    By namyad in forum C++ Programming
    Replies: 2
    Last Post: 11-16-2010, 11:17 AM
  2. Multiple-Choice Exam Program
    By micmagicfly in forum C++ Programming
    Replies: 7
    Last Post: 03-26-2010, 01:17 PM
  3. multiple choice
    By iLike in forum C Programming
    Replies: 6
    Last Post: 10-30-2009, 03:53 PM
  4. Multiple Choice!!!
    By doubleanti in forum A Brief History of Cprogramming.com
    Replies: 7
    Last Post: 09-08-2002, 02:30 PM

Tags for this Thread