jeudi 15 juin 2017

How to Randomize cout Outputs c++

I am using Eclipse 4.6.3 on Mac OS Sierra.

So I have this code:

int main() {

int GameState = ROOM1;
int iRoomCounter[4] = {0,0,0}; // Used to determine if a room has been visited.
string choice;
char Name[25];
cout << "!!!Hello World!!!" << endl;
cout << "Enter Your Name!" << endl;
cin >> Name;
cout << "Thank you " << Name << ". You will not be forgotten." << endl;

while(GameState != DEATH)
{
        switch(GameState)
{
                case ROOM1:
                {

                    if (iRoomCounter[0] == 0) {
cout << "\n One day, " << Name << " was walking through a field and spotted a little Ejay." << endl;
cout << Name << " also spotted a cat. He wanted to pet both, but he could only pet one." << endl;
iRoomCounter[0] = 1;
}
cout << "\nWhich one will he pet?" << endl;
cout << "Ejay" << endl;
cout << "Cat" << endl;
cout << "-> ";
cin >> choice;
    if(choice == "Ejay" || choice == "ejay")
{
    cout << "He pet Ejay" << endl;

I have two questions. If you answer only one question, that is fine. Yet I would like for someone to answer the other question.

  1. I would like to randomize certain outputs, for example: If I choose "Ejay", I would like it to either say "He pet Ejay" or "Ejay ran away." or "Ejay died." I am not sure how to do that. Will someone so kindly implement a way to do that in my code? Thank you in advance.

  2. I have been struggling to figure out how to export my code into an application. I have researched and researched, and could not find anything. I am using Eclipse on a Mac, so that may be part of the reason. Will someone tell me how to do it?

Thank you everyone!




Aucun commentaire:

Enregistrer un commentaire