Creating simple text games???

Simo

Warlord
Joined
Mar 5, 2002
Messages
215
Location
Sydney
I am interested in making some simple text games just as a novelty. I remember back from my school days things like this example:

'Do you enter cave' y/n
if y do this
if no do this etc etc

I am just after simple programming to start with as a bit of fun, things have probably changed a lot since I was at school and may not even be done like that anymore. Possible adding pictures may be easy now, I dont know. Where would be a good place to start learning as I am a complete novice?

Thank you.
 
C++, while it can be utterly confusing, can also be used for easy text games (I've made some: Jeopardy, A Trivia Game, etc.)

You need a compiler (I recommend Dev C++, it's free and easy to use), but then you're pretty much set. C/C++ Programming has some good beginner tutorials that I used. The basics you'll use:

#include <iostream> // this is a comment -- iostream is input/output stream, needed for basic stuff

using namespace std; // this says instead of having to write std::cout << "bla"; all the time, you can just write cout << "bla"; MUCH easier.

int main(void) // the main place where the program runs
{ // starts it
int a, b, c; // variables, of type integer
cout << "Enter cave? 1 = Yes/2 = No"; // write that line
cin >> a; // take in a's value, after a user enters a 1 or 2 and hits enter

if (a == 1)
{
//etc...
cout << "hi"; // write 'hi'
}

if (a == 2)
{
//etc...
}

else
{
cout << "You didn't enter 1 or 2!";
}

} // closes int main()

Regarding pictures, I'm not sure ... hope this helps. Remember to close most lines with a semicolon, ; , but not all lines (like loops if, else, while, for, etc.,).

I'll post some source code of my text games in a bit. :)
 
C++ is probably on the complicated side for something like this, because it has a lot of Microsoft-isms for their many Windows APIs which are excess to requirements.

If you are learning, then PASCAL might be easier. It has a strong-typed syntax meaning it's easier to read and isn't packed with Microsoft-isms. PASCAL exists in many competing versions, all similar but with slight differences. Examples include: FreePascal, GNU-Pascal, Turbo Pascal, Extended Pascal, and many more. Delphi is a version of PASCAL that is packed with Microsoft-isms.

C is probably a good language to learn because it is well supported and many newer languages are derived directly from it: i.e. Java, C++, Objective C, &c. However, the syntax isn't as easy to learn as PASCAL.

There are families of languages, all sharing similar syntax. Programmers normally become accustomed to one and then stick with it, and others like it.

I would split the common families into: C, PASCAL, PERL, LISP, COBOL. If you know one then the others in it's family will look familiar, but the other families will still look completely foreign.
 
That's my point, and C++ documentation will be complicated with redundant information.
 
You should start with C++ because you're going to have to learn it anyway if you decide to get into serious programming (like me).

And ya'll stop being such sissies about C++. I think it is easier to learn than Pascal or BASIC even because C++ is more structured and easier to read. The only hard thing about the sytax in C++ when you're a beginner is pointers and I highly doubt he will be using pointers in his program.

In fact, right now, I'm starting to make a text based board game (just came up with the idea like 10 minutes ago). I'll post it if I can finish it soon.
 
Ginger_Ale said:
Regarding pictures, I'm not sure ... hope this helps. Remember to close most lines with a semicolon, ; , but not all lines (like loops if, else, while, for, etc.,).

I'll post some source code of my text games in a bit. :)

In ANSI/ISO standard C++ there is no graphics, sound, nor even changing font colors. Here is a tutorial if you want to learn how to change font colors and do other stuff with the console (you actually go about this by using Windows API functions, but it's extremely simple). If you want to use graphics, you're going to have to learn an API like DirectX or Allegro to do it, which I don't recommend for beginners.

Ginger_Ale, all C++ statements end in ; not just a random selection of things.
 
Yes, all statements, couldn't think of a good way to word it.

Here is a text trivia game I made - no pointers. They confuse me and I don't understand them. :P The basics of C++ aren't that hard to learn, like homeyg said.
[beware, it is long]
Spoiler Trivia Game :

Code:
#include <iostream>

using namespace std;

char* test(char* option); 

int main(int argc, char* argv[])

{
    char menu[4] = "Yes";
      
    while ( strcmp (menu, "No") != 0)
    {
        char option[5];
        
        cout << "Trivia Game!\n";
        cin.get();
        cout << "Please choose an option: ";
        cout << "\nPlay\nQuit";
        cout << "\nYour choice: ";
        cin.getline (option, 5, '\n' );
           
            while ( strcmp (test(option), "QUIT") != 0)
            {
            cout << "Hit ENTER to play!";
            cin.get();
            
            // ============================== START FIRST QUESTION ==============================
             
            char questionone[50] = "\nWhat country is Tsing Tao beer brewed in?";
            char answerone[20];
            
            cout << " " << questionone << " ";
            cout << "\nYour answer: ";
            cin.getline (answerone, 20, '\n');
            
            // ================================ START ANSWERS ===================================
            if ( strcmp (test(answerone), "CHINA") == 0 )
            {
                cout << "Correct!";
                cin.get();
            }
            
            else
            {
                cout << "Wrong!  It was China!";
                cin.get();
            }
            
            // ================================= END ANSWERS, FIRST QUESTION =====================
            
            cout << "\nContinue to Play or Quit?"; 
            cout << "\nYour choice: ";      
            cin >> option;
            
            if (strcmp (test(option), "QUIT") == 0)
            {
                return 0;
            }
            
            else
            {
            }        
            
            // ================================== START SECOND QUESTION ===========================
            
            char questiontwo[100] = "\nWhat color belt does an improving judo practitioner trade in for brown?";
            char answertwo[20];
            
            cout << " " << questiontwo << " ";
            cout << "\nYour answer: ";
            cin >> answertwo;
            cout << "";
            
            // ================================== START ANSWERS ====================================
            
            if (strcmp (test(answertwo), "BLUE") == 0)
            {
                cout << "Correct!\n";
                cin.get();
            }
            
            else
            {
                cout << "Wrong!  It was blue!";
                cin.get();
            } 
            
            
            // =================================== END ANSWERS, SECOND QUESTION =====================
            
            cin.get(); 
            cout << "Continue to Play or Quit?";
            cout << "\nYour choice: ";
            cin >> option;
            
            if (strcmp (test(option), "QUIT") == 0)
            {
                return 0;
            }
            
            else
            {
            }
            
            // =================================== START THIRD QUESTION =============================
            
            char questionthree[100] = "\nWhat Asian island country boasts the most followers of Mohammed?";
            char answerthree[20];
            
            cout << " " << questionthree << " ";
            cout << "\nYour answer: ";
            cin >> answerthree;
            cout << "";
            
            // ================================== START ANSWERS ====================================
            
            if (strcmp (test(answerthree), "INDONESIA") == 0)
            {
                cout << "Correct!\n";
                cin.get();
            }
            
            else
            {
                cout << "Wrong!  It was Indonesia!";
                cout << "";
                cin.get();
            } 
            
            
            // =================================== END ANSWERS, THIRD QUESTION =====================
            
            cin.get();
            cout << "\nContinue to Play or Quit?";
            cout << "\nYour choice: ";
            cin >> option;
            
            if (strcmp (test(option), "QUIT") == 0)
            {
                return 0;
            }
            
            else
            {
            }
            
            // =================================== START FOURTH QUESTION =============================
            
            char questionfour[100] = "\nWhat does 'secco' mean on a bottle of Italian wine?";
            char answerfour[20];
            
            cout << " " << questionfour << " ";
            cout << "\nYour answer: ";
            cin >> answerfour;
            cout << "";
            
            // ================================== START ANSWERS ====================================
            
            if (strcmp (test(answerfour), "DRY") == 0)
            {
                cout << "Correct!\n";
                cin.get();
            }
            
            else
            {
                cout << "Wrong!  It means 'Dry'!";
                cin.get();
            } 
            
            
            // =================================== END ANSWERS, FOURTH QUESTION =====================
            
            cin.get();
            cout << "Continue to Play or Quit?";
            cout << "\nYour choice: ";
            cin >> option;
            
            if (strcmp (test(option), "QUIT") == 0)
            {
                return 0;
            }
            
            else
            {
            }
            
            // =================================== START FIFTH QUESTION =============================
            
            char questionfive[100] = "\nWhat European country, apart from Vatican City, flies a square flag?";
            char answerfive[20];
            
            cout << " " << questionfive << " ";
            cout << "\nYour answer: ";
            cin >> answerfive;
            cout << "";
            
            // ================================== START ANSWERS ====================================
            
            if (strcmp (test(answerfive), "SWITZERLAND") == 0)
            {
                cout << "Correct!\n";
                cin.get();
            }
            
            else
            {
                cout << "Wrong!  It was Switzerland!";
                cin.get();
            } 
            
            
            // =================================== END ANSWERS, FIFTH QUESTION =====================
            
            cin.get();
            cout << "Continue to Play or Quit?";
            cout << "\nYour choice: ";
            cin >> option;
            
            if (strcmp (test(option), "QUIT") == 0)
            {
                return 0;
            }
            
            else
            {
            }
            
            // =================================== START SIXTH QUESTION =============================
            
            char questionsix[100] = "\nHow many South American countries have the letter 'Z' in their names?";
            char answersix[20];
            
            cout << " " << questionsix << " ";
            cout << "\nYour answer: ";
            cin >> answersix;
            cout << "";
            
            // ================================== START ANSWERS ====================================
            
            if (strcmp (test(answersix), "TWO") == 0)
            {
                cout << "Correct!  Venezuela and Brazil!\n";
                cin.get();
            }
            
            else
            {
                cout << "Wrong!  They are Venezuela and Brazil!";
                cin.get();
            } 
            
            
            // =================================== END ANSWERS, SIXTH QUESTION =====================
            
            cin.get();
            cout << "Continue to Play or Quit?";
            cout << "\nYour choice: ";
            cin >> option;
            
            if (strcmp (test(option), "QUIT") == 0)
            {
                return 0;
            }
            
            else
            {
            }
            
            // =================================== START SEVENTH QUESTION =============================
            
            char questionseven[100] = "\nWhich is older - chess or checkers?";
            char answerseven[20];
            
            cout << " " << questionseven << " ";
            cout << "\nYour answer: ";
            cin >> answerseven;
            cout << "";
            
            // ================================== START ANSWERS ====================================
            
            if (strcmp (test(answerseven), "CHECKERS") == 0)
            {
                cout << "Correct!\n";
                cin.get();
            }
            
            else
            {
                cout << "Wrong!  It was Checkers!";
                cin.get();
            } 
            
            
            // =================================== END ANSWERS, SEVENTH QUESTION =====================
            
            cin.get();
            cout << "Continue to Play or Quit?";
            cout << "\nYour choice: ";
            cin >> option;
            
            if (strcmp (test(option), "QUIT") == 0)
            {
                return 0;
            }
            
            else
            {
            }
            
            // =================================== START EIGHTH QUESTION =============================
            
            char questioneight[100] = "\nWhat European city are you heading for if your baggage tags read AMS?";
            char answereight[20];
            
            cout << " " << questioneight << " ";
            cout << "\nYour answer: ";
            cin >> answereight;
            cout << "";
            
            // ================================== START ANSWERS ====================================
            
            if (strcmp (test(answereight), "AMSTERDAM") == 0)
            {
                cout << "Correct!\n";
                cin.get();
            }
            
            else
            {
                cout << "Wrong!  It was Amsterdam!";
                cin.get();
            } 
            
            
            // =================================== END ANSWERS, EIGHTH QUESTION =====================
            
            cin.get();
            cout << "Continue to Play or Quit?";
            cout << "\nYour choice: ";
            cin >> option;
            
            if (strcmp (test(option), "QUIT") == 0)
            {
                return 0;
            }
            
            else
            {
            }
            
            // =================================== START NINETH QUESTION =============================
            
            char questionnine[100] = "\nWhat color appears on the flags of all Islamic countries?";
            char answernine[20];
            
            cout << " " << questionnine << " ";
            cout << "\nYour answer: ";
            cin >> answernine;
            cout << "";
            
            // ================================== START ANSWERS ====================================
            
            if (strcmp (test(answernine), "GREEN") == 0)
            {
                cout << "Correct!\n";
                cin.get();
            }
            
            else
            {
                cout << "Wrong!  It was Green!";
                cin.get();
            } 
            
            
            // =================================== END ANSWERS, NINETH QUESTION =====================
            
            cin.get();
            cout << "Continue to Play or Quit?";
            cout << "\nYour choice: ";
            cin >> option;
            
            if (strcmp (test(option), "QUIT") == 0)
            {
                return 0;
            }
            
            else
            {
            }
            
            // =================================== START TENTH QUESTION =============================
            
            char questionten[100] = "\nWhat travel in gaggles?";
            char answerten[20];
            
            cout << " " << questionten << " ";
            cout << "\nYour answer: ";
            cin >> answerten;
            cout << "";
            
            // ================================== START ANSWERS ====================================
            
            if (strcmp (test(answerten), "GEESE") == 0)
            {
                cout << "Correct!\n";
                cin.get();
            }
            
            else
            {
                cout << "Wrong!  It was Geese!";
                cin.get();
            } 
            
            
            // =================================== END ANSWERS, TENTH QUESTION =====================
            
            cin.get();
            cout << "Continue to Play or Quit?";
            cout << "\nYour choice: ";
            cin >> option;
            
            if (strcmp (test(option), "QUIT") == 0)
            {
                return 0;
            }
            
            else
            {
            }
            
            
            
            
            cin.get();
            cout << "\nThank you for playing.  I hope you enjoyed it.";
            cin.get();
            return 0;
                                      
        }
        
        while ( strcmp (test(option), "QUIT") == 0)
        {
            return 0;
        }    
               
    }    
}


char* test(char* option)
{
	// Set up the temporary variables
	int i, length;
	length = strlen(option);

	// Loop through the word, making each letter uppercase
	for (i=0; i<length; i++)
	{
		option[i] = toupper(option[i]);
	}

	// Return the string
	return option;
}
 
What are you talking about? The function test() uses pointers.
 
C++ is not well structured at all. Single brackets, seperated by many lines containing other single brackets, is quite terse. The words BEGIN and END are much easier to work with.

Pointers are common to most programming languages. There is no way to avoid pointers, unless you stick to real-time interpreted scripts.

Incindentally, a text game would be quicker to develop using an interpreted language because there would be fewer files to mess with, and a transparent compiling process, and simplified (online) deployment. Having said that, people should stick with what they are used to, to avoid undue complications or possible disapointment.
 
homeyg said:
What are you talking about? The function test() uses pointers.

That wasn't my code, I just used it so answers wouldn't be case sensitive. ;)

PS: Nice site you led me to about colors - very interesting, didn't know that was possible in a "window".
 
stormbind said:
C++ is not well structured at all. Single brackets, seperated by many lines containing other single brackets, is quite terse. The words BEGIN and END are much easier to work with.

Pointers are common to most programming languages. There is no way to avoid pointers, unless you stick to real-time interpreted scripts.

Incindentally, a text game would be quicker to develop using an interpreted language because there would be fewer files to mess with, and a transparent compiling process, and simplified (online) deployment. Having said that, people should stick with what they are used to, to avoid undue complications or possible disapointment.

C++ is very structured if you use correct form with indentions and whitespace. ;)
 
I also think that suggesting serious programming isn't possible without C++ is very poor form.

MacOS was written in Pascal. I would think it funny if you think creating an operating system isn't proper programming.

Modern MacOS X applications are written in Objective C which is widely considered more advanaced than Microsoft C++.

Most programs are written in COBOL but that includes really old stuff so best to skip that. COBOL was originally intended for non-technical end-user programming.

Most operating systems are written in C. Most GNU desktop applications are written in C. Very popular among anti-Microsoft programmers.

Most consumer-orientated retail applications are written in C++. The reason for this is, C++ is cheaper for making new apps because Microsoft have good support. However, it is difficult to maintain. This is why there are more new versions than old updates.

Most scripts are written in PERL.

C++ is definately big, but I iterate my view that it's bad to suggest it in someway has a monopoly.
 
Okay that was just my opinion, maybe it was a bad one.
 
homeyg said:
C++ is very structured if you use correct form with indentions and whitespace. ;)
Ok, but I have been known to crank up the old MS EDIT which is a bit weak for indentations ;)

The tool I prefer for that kind of stuff is the credit text editor (freeware) which supports all languages. I don't have a URL but Google will. Maybe this will help Simo more than my other ramblings :)
 
I just started a game (I think I already said that), a text based strategy game, and I'll post the code that I have so far after a half an hour of programming (it's at the point where it's runnable). Basically, it's a nuclear war game, and so far the program chooses 30 random squares to be designated type residential 'R' and 4 random squares to be of type military 'M'. In the finished game, these will be hidden, all you will have is certain clues. You choose one square to nuke per turn (choose based on clues) and each turn a few squares will actually be revealed. The effects of the nuke are kindof like Civ except there's no destruction going on; all of the squares around the nuked square and that square itself are contaminated. If you contaminate residential squares your 'reputation' goes down, if you hit military squares, your reputation goes up. The game ends when all military squares are contaminated. What I mean by contaminated basically signifies that the square is destroyed.

Here's the code if anyone wants to see (Simo might find it useful, but it might be a little advanced since he said he was just starting out):

Code:
#include <iostream>
#include <ctime>
#include <cstdlib>

using namespace std;

enum typeTile {residentialArea, militarySite, none};

const int BOARDSIZE = 9;
const int NUMOFRES = 30;
const int NUMOFMIL = 4;
const char MILI = 'M';
const char RESI = 'R';
const char NONE = ' ';

struct resTilePlaceHolder
{
    int x;
    int y;
};

struct milTilePlaceHolder
{
    int x;
    int y;
};

struct tile
{
    bool tileContaminated;
    char tileSymbol;
    typeTile type;
    bool occupied;
};



resTilePlaceHolder resMemArray[30];
milTilePlaceHolder milMemArray[3];
char displayBoard[BOARDSIZE][BOARDSIZE];
tile actuBoard[BOARDSIZE][BOARDSIZE];

void initializeActuBoard();
void displayCharBoard();

int main(int argc, char* argv[])
{
    int noOfNukesLeft = 3;
    int reputation = 30;
    
    initializeActuBoard();
    
    for(int i = 0; i<BOARDSIZE; i++)
    {
        for(int j = 0; j<BOARDSIZE; j++)
        {
            switch(actuBoard[i][j].type)
            {
                case residentialArea:
                    displayBoard[i][j] = RESI;
                    break;
                case militarySite:
                    displayBoard[i][j] = MILI;
                    break;
                case none:
                    displayBoard[i][j] = NONE;
            }
        }
    }
    
    displayCharBoard();
    cin.get();
    return 0; 
}

void initializeActuBoard()
{
    time_t seconds;
    time(&seconds);
    srand((unsigned int)seconds);
    int randX;
    int randY;
    
    for(int i = 0; i<BOARDSIZE; i++)
    {
        for(int j = 0; j<BOARDSIZE; j++)
        {
            actuBoard[i][j].type = none;
        }
    }
    
    for(int i = 0; i<BOARDSIZE; i++)
    {
        for(int j = 0; j<BOARDSIZE; j++)
        {
            actuBoard[i][j].occupied = false;
        }
    }
    
    int i = 0; 
    
    while(i<NUMOFRES)
    {
        randX = 1+rand()%9;
        randY = 1+rand()%9;
        randX = randX-1;
        randY = randY-1; 
        
        if(actuBoard[randY][randX].occupied == false)
        {
            actuBoard[randY][randX].type = residentialArea;
            resMemArray[i].x = randX;
            resMemArray[i].y = randY;
            actuBoard[randY][randX].occupied = true;
            i++;
        }
        else if(actuBoard[randY][randX].occupied != false)
        {
            continue;
        }
        
    }
    
    i = 0;
    
    while(i<NUMOFMIL)
    {
        randX = 1+rand()%9;
        randY = 1+rand()%9;
        randX = randX-1;
        randY = randY-1;
        
        if(actuBoard[randY][randX].occupied == false)
        {
            actuBoard[randY][randX].type = militarySite;
            milMemArray[i].x = randX;
            milMemArray[i].y = randY;
            actuBoard[randY][randX].occupied = true;
            i++;
        }
        else if(actuBoard[randY][randX].occupied != false)
        {
            continue;
        }
        
    }
}

void displayCharBoard()
{
    for(int i = 0; i<BOARDSIZE; i++)
    {
        for(int j = 0; j<BOARDSIZE; j++)
        {
            cout<<"["<<displayBoard[i][j]<<"]";
        }
        cout<<endl;
    }
}
 
hmm, Ginger_Ale, I looked more closely at the code you posted and noticed that it has alot of wierd/needless things going on with it. Example:

Code:
// ================================= END ANSWERS, FIRST QUESTION =====================
            
            cout << "\nContinue to Play or Quit?"; 
            cout << "\nYour choice: ";      
            cin >> option;
            
            if (strcmp (test(option), "QUIT") == 0)
            {
                return 0;
            }
            
            else
            {
            }

The else statement isn't needed there (they do that several times in the code).

Code:
while ( strcmp (test(option), "QUIT") == 0)
{
     return 0;
}

I don't think this has any meaning either because you can only exit a program once. It needs to be changed to an if statement.
 
Not to be a nit picker or anything, but I closely looked over the code again, and there is a massive amount of logic problems especially in the setup of the while loops. I redid the code for you to see (I'm sorry, when I see improper code I have the irresistable urge to fix it! :rotfl: ):

Code:
#include <iostream>

using namespace std;

char* test(char* option);

int main(int argc, char* argv[])
{
        char option[5];

        cout << "Trivia Game!\n";
        cin.get();
        cout << "Please choose an option: ";
        cout << "\nPlay\nQuit";
        cout << "\nYour choice: ";
        cin.getline (option, 5, '\n' );

        while (strcmp (test(option), "QUIT")!=0)
        {
            cout << "Hit ENTER to play!";
            cin.get();

            // ============================== START FIRST QUESTION ==============================

            char questionone[50] = "\nWhat country is Tsing Tao beer brewed in?";
            char answerone[20];

            cout << " " << questionone << " ";
            cout << "\nYour answer: ";
            cin.getline (answerone, 20, '\n');

            // ================================ START ANSWERS ===================================
            if ( strcmp (test(answerone), "CHINA") == 0 )
            {
                cout << "Correct!";
                cin.get();
            }

            else
            {
                cout << "Wrong!  It was China!";
                cin.get();
            }

            // ================================= END ANSWERS, FIRST QUESTION =====================

            cout << "\nContinue to Play or Quit?";
            cout << "\nYour choice: ";
            cin >> option;

            if (strcmp (test(option), "QUIT") == 0)
            {
                return 0;
            }



            // ================================== START SECOND QUESTION ===========================

            char questiontwo[100] = "\nWhat color belt does an improving judo practitioner trade in for brown?";
            char answertwo[20];

            cout << " " << questiontwo << " ";
            cout << "\nYour answer: ";
            cin >> answertwo;
            cout << "";

            // ================================== START ANSWERS ====================================

            if (strcmp (test(answertwo), "BLUE") == 0)
            {
                cout << "Correct!\n";
                cin.get();
            }

            else
            {
                cout << "Wrong!  It was blue!";
                cin.get();
            }


            // =================================== END ANSWERS, SECOND QUESTION =====================

            cin.get();
            cout << "Continue to Play or Quit?";
            cout << "\nYour choice: ";
            cin >> option;

            if (strcmp (test(option), "QUIT") == 0)
            {
                return 0;
            }



            // =================================== START THIRD QUESTION =============================

            char questionthree[100] = "\nWhat Asian island country boasts the most followers of Mohammed?";
            char answerthree[20];

            cout << " " << questionthree << " ";
            cout << "\nYour answer: ";
            cin >> answerthree;
            cout << "";

            // ================================== START ANSWERS ====================================

            if (strcmp (test(answerthree), "INDONESIA") == 0)
            {
                cout << "Correct!\n";
                cin.get();
            }

            else
            {
                cout << "Wrong!  It was Indonesia!";
                cout << "";
                cin.get();
            }


            // =================================== END ANSWERS, THIRD QUESTION =====================

            cin.get();
            cout << "\nContinue to Play or Quit?";
            cout << "\nYour choice: ";
            cin >> option;

            if (strcmp (test(option), "QUIT") == 0)
            {
                return 0;
            }



            // =================================== START FOURTH QUESTION =============================

            char questionfour[100] = "\nWhat does 'secco' mean on a bottle of Italian wine?";
            char answerfour[20];

            cout << " " << questionfour << " ";
            cout << "\nYour answer: ";
            cin >> answerfour;
            cout << "";

            // ================================== START ANSWERS ====================================

            if (strcmp (test(answerfour), "DRY") == 0)
            {
                cout << "Correct!\n";
                cin.get();
            }

            else
            {
                cout << "Wrong!  It means 'Dry'!";
                cin.get();
            }


            // =================================== END ANSWERS, FOURTH QUESTION =====================

            cin.get();
            cout << "Continue to Play or Quit?";
            cout << "\nYour choice: ";
            cin >> option;

            if (strcmp (test(option), "QUIT") == 0)
            {
                return 0;
            }



            // =================================== START FIFTH QUESTION =============================

            char questionfive[100] = "\nWhat European country, apart from Vatican City, flies a square flag?";
            char answerfive[20];

            cout << " " << questionfive << " ";
            cout << "\nYour answer: ";
            cin >> answerfive;
            cout << "";

            // ================================== START ANSWERS ====================================

            if (strcmp (test(answerfive), "SWITZERLAND") == 0)
            {
                cout << "Correct!\n";
                cin.get();
            }

            else
            {
                cout << "Wrong!  It was Switzerland!";
                cin.get();
            }


            // =================================== END ANSWERS, FIFTH QUESTION =====================

            cin.get();
            cout << "Continue to Play or Quit?";
            cout << "\nYour choice: ";
            cin >> option;

            if (strcmp (test(option), "QUIT") == 0)
            {
                return 0;
            }



            // =================================== START SIXTH QUESTION =============================

            char questionsix[100] = "\nHow many South American countries have the letter 'Z' in their names?";
            char answersix[20];

            cout << " " << questionsix << " ";
            cout << "\nYour answer: ";
            cin >> answersix;
            cout << "";

            // ================================== START ANSWERS ====================================

            if (strcmp (test(answersix), "TWO") == 0)
            {
                cout << "Correct!  Venezuela and Brazil!\n";
                cin.get();
            }

            else
            {
                cout << "Wrong!  They are Venezuela and Brazil!";
                cin.get();
            }


            // =================================== END ANSWERS, SIXTH QUESTION =====================

            cin.get();
            cout << "Continue to Play or Quit?";
            cout << "\nYour choice: ";
            cin >> option;

            if (strcmp (test(option), "QUIT") == 0)
            {
                return 0;
            }



            // =================================== START SEVENTH QUESTION =============================

            char questionseven[100] = "\nWhich is older - chess or checkers?";
            char answerseven[20];

            cout << " " << questionseven << " ";
            cout << "\nYour answer: ";
            cin >> answerseven;
            cout << "";

            // ================================== START ANSWERS ====================================

            if (strcmp (test(answerseven), "CHECKERS") == 0)
            {
                cout << "Correct!\n";
                cin.get();
            }

            else
            {
                cout << "Wrong!  It was Checkers!";
                cin.get();
            }


            // =================================== END ANSWERS, SEVENTH QUESTION =====================

            cin.get();
            cout << "Continue to Play or Quit?";
            cout << "\nYour choice: ";
            cin >> option;

            if (strcmp (test(option), "QUIT") == 0)
            {
                return 0;
            }



            // =================================== START EIGHTH QUESTION =============================

            char questioneight[100] = "\nWhat European city are you heading for if your baggage tags read AMS?";
            char answereight[20];

            cout << " " << questioneight << " ";
            cout << "\nYour answer: ";
            cin >> answereight;
            cout << "";

            // ================================== START ANSWERS ====================================

            if (strcmp (test(answereight), "AMSTERDAM") == 0)
            {
                cout << "Correct!\n";
                cin.get();
            }

            else
            {
                cout << "Wrong!  It was Amsterdam!";
                cin.get();
            }


            // =================================== END ANSWERS, EIGHTH QUESTION =====================

            cin.get();
            cout << "Continue to Play or Quit?";
            cout << "\nYour choice: ";
            cin >> option;

            if (strcmp (test(option), "QUIT") == 0)
            {
                return 0;
            }



            // =================================== START NINETH QUESTION =============================

            char questionnine[100] = "\nWhat color appears on the flags of all Islamic countries?";
            char answernine[20];

            cout << " " << questionnine << " ";
            cout << "\nYour answer: ";
            cin >> answernine;
            cout << "";

            // ================================== START ANSWERS ====================================

            if (strcmp (test(answernine), "GREEN") == 0)
            {
                cout << "Correct!\n";
                cin.get();
            }

            else
            {
                cout << "Wrong!  It was Green!";
                cin.get();
            }


            // =================================== END ANSWERS, NINETH QUESTION =====================

            cin.get();
            cout << "Continue to Play or Quit?";
            cout << "\nYour choice: ";
            cin >> option;

            if (strcmp (test(option), "QUIT") == 0)
            {
                return 0;
            }



            // =================================== START TENTH QUESTION =============================

            char questionten[100] = "\nWhat travel in gaggles?";
            char answerten[20];

            cout << " " << questionten << " ";
            cout << "\nYour answer: ";
            cin >> answerten;
            cout << "";

            // ================================== START ANSWERS ====================================

            if (strcmp (test(answerten), "GEESE") == 0)
            {
                cout << "Correct!\n";
                cin.get();
            }

            else
            {
                cout << "Wrong!  It was Geese!";
                cin.get();
            }


            cout << "The game is over, would you like to play again?"<<endl;
            cout << "Play? or Quit?"<<endl;
            cin >> option;
            cin.get();





        }

        cin.get();
        cout << "\nThank you for playing.  I hope you enjoyed it.";
        cin.get();
        return 0;

}


char* test(char* option)
{
        // Set up the temporary variables
        int i, length;
        length = strlen(option);

        // Loop through the word, making each letter uppercase
        for (i=0; i<length; i++)
        {
                option[i] = toupper(option[i]);
        }

        // Return the string
        return option;
}

I reduced the structure of the program to one while loop instead of two.

I made much larger errors when I was starting out though... One time, when I was writing my Connect Four program, I made such a large logic error that it took me 4 hours to sort though the 900 lines of code and fix one problem that had like 400 instances in the code (the problem was the way the test conditions for all 400 if statements was setup).

EDIT: Now that I think about it, my analysis shouldn't have been so harsh. :blush:
 
Back
Top Bottom