Build a Text Adventure Challenge Project (C++)

I finally was able to finish this project. But I’m glad I’m learning.

#include <iostream>

int main () {

   char ch1;
   char q2;  //// Not answered yet
   char q3;  //// Not answered yet

   //// Question 1  
   std::cout << "Welcome to My Program. \n";
   std::cout << "Everyday we wake up in a particular mood that leads our day for the most part. \n";
   std::cout << "Which mood are you waking up to? \n \n";
   std::cout << "A.) Angry \n";
   std::cout << "B.) Blah \n";
   std::cout << "C.) Happy \n";

   std::cin >> ch1;

if (ch1 == 'a' || ch1 == 'A') {
       std::cout << "We are off to a bad start, Everyone    sucks. \n\n";
       std::cout << "What are you going to do next to change your day? \n";
       std::cout << "A.) GO GET COFFEE!! \n";
       std::cout << "B.) Just Go to Work \n";
       std::cout << "C.) Go Back To Sleep \n";

       std::cin >> q2;

       
       // Q2 question
       if (q2 == 'a' || q2 == 'A') {
           std::cout << "Things Look Better, You might survive";
       } else if (q2 == 'b' || q2 == 'B') {
           std::cout << "You're a Ticking Time Bomb!";
       } else if ( q2 == 'c' || q2 == 'C') {
           std::cout << "Nothing can beat sleep!!" ;
       } else {
           std::cout <<"Error, Not A Choice" ;
       }


}

if(ch1 == 'b' || ch1 == 'B'){
       std::cout << "Nothing seems to motivate you and all you want to do is lay in bed. \n";

       std::cout << "What are you going to do next to change your day? \n";
       std::cout << "A.) GO GET COFFEE!! \n";
       std::cout << "B.) Ditch work to go to the beach! \n";
       std::cout << "C.) Go Back To Sleep \n";

       std::cin >> q3;


       ///Question 3
       if (q3 == 'a' || q3 == 'A') {
           std::cout << "Things Look Better, You might survive";
       } else if (q3 == 'b' || q3 == 'B') {
           std::cout << "You're day Just got Better! Enjoy!" ;
       } else if ( q3 == 'c' || q3 == 'C') {
           std::cout << "Nothing can beat sleep!!"; 
       } else {
           std::cout <<"Error, Not A Choice ----";
       }
}

if ( ch1 == 'c' || ch1 == 'C') {
       std::cout << "Nothing Can Ruin Your Day!! \n";
       std::cout << "ENJOY!! \n";
       

}


int d;

for(d=0 ; d <= 10 ; d++)
{
  std::cout << "THANK YOU \n";
}
}

A simple bear encounter CMD game I made.
Bear_Encounter_CMD_Game/bear_encounter_cmd_game.cpp at main · GilDaniel/Bear_Encounter_CMD_Game · GitHub)

/*
    Bear Encounter Game- For Windows
                                    */

#include <iostream>
#include <windows.h>
#include <ctime>
int main(){
    srand(time(NULL));
    std::cout << "===================================\n";
    std::cout << "======CMD Game- BY Gil Daniel======\n";
    std::cout << "===================================\n\n";

    std::cout << "You are walking in the woods and see a bear going towards you, what will you do?\n";
    
    std::cout << "A)  Run to the opposite direction\n";
    std::cout << "B)  Try to see it's color\n";
    std::cout << "C)  Raise your arms up\n\n\n";

    std::cout << "Type the answer letter\n";

    char userinput;
    bool asking = true;
    while(asking){
        
        std::cin >> userinput;
        switch (userinput)
        {
        case 'A':
            
            std::cout <<"The bear now started to chase you. What will you do ?\n";
            asking = false;
        break;
        case 'B':
            std::cout<< "It's a brown bear, and it get nearer. What will you do ?\n";
            asking = false;
        break;

        case 'C':
            std::cout <<"The bear became confused, but continue to go in your direction. What will you do ?\n";
            asking = false;
        break;
        default:
            std::cout <<"Invalid, try to type 'A','B' or 'C'\n";
            asking = true;
            break;
        }
    }
    if (userinput == 'A')
    {
        std::cout <<"A) Run faster.\n";
        std::cout <<"B) Hide behind a tree.\n";
        std::cout <<"C) Throw a rock.\n";
        bool asking2 = true;
        while (asking2)
        {
        char input2;
        std::cin >> input2;
        
        switch (input2)
        {
        case 'A':
            std::cout <<"You ran faster\n";
            Sleep(2000);
            std::cout <<"===================================\n";
            std::cout <<"==The bear reach you and you die.==\n";
            std::cout <<"===================================\n";
            Sleep(1000);
            asking2 = false;
            return 0;
            break;
        case 'B':
            std::cout << "You hide behind a tree.\n";
            Sleep(3000);
            std::cout <<"===================================\n";
            std::cout <<"The bear sniffed and kill you\n";
            std::cout <<"===================================\n";
            
            Sleep(1000);
            asking2 = false;
            return 0;
            
            break;
        case 'C':
            std::cout << "You Throw a rock\n";
            Sleep(1000);
            int chance;
            chance = rand() % 100;
            if(chance < 30){
                std::cout <<"===========================================\n";
                std::cout <<"==By a unbelivable luck the bear run away==\n";
                std::cout <<"===========================================\n";
                Sleep(2000);
                std::cout <<"===================================\n";
                std::cout <<"============You Survive!===========\n";
                std::cout <<"===================================\n";
                 
                Sleep(3000);
                asking2 = false;
                return 0;           
                }
            else{
                
                std::cout <<"===================================\n";
                std::cout <<"==The bear reach you and you die.==\n";
                std::cout <<"===================================\n";
                Sleep(1000);
                asking2 = false;
                return 0;
            }
            break;
            default:
                std::cout << "Invalid, try to type 'A','B' or 'C'\n";
                asking2 = true;
            break;
                
        }
        }
    }
        if (userinput == 'B')
        {
        Sleep(1000);
        std::cout <<"A) Post on TikTok\n";
        std::cout <<"B) Scream.\n";
        std::cout <<"C) Throw a rock.\n";
        
        char input3;
        
        bool asking3 = true;
        while (asking3)
        {
        std::cin >> input3;
        switch (input3)
        {
        case 'A':
            std::cout <<"You film the bear that suddenty starts dancing.\n";
            Sleep(5000);
            std::cout <<"================================================\n";
            std::cout <<"==The bear remember it is hungry and kill you.==\n";
            std::cout <<"================================================\n";
            Sleep(1000);
            asking3 = false;
            return 0;
            break;
        case 'B':
            std::cout << "You scream a lot.\n";
            Sleep(3000);
            std::cout <<"===================================\n";
            std::cout <<"==The bear don't like it and run.==\n";
            std::cout <<"===================================\n";
            Sleep(1000);
            std::cout <<"===================================\n";
            std::cout <<"============You Survive!===========\n";
            std::cout <<"===================================\n";
            asking3 = false;
            Sleep(3000);
            return 0;
            break;
        case 'C':
            std::cout << "You Throw a rock\n";
            Sleep(1000);
            int chance2;
            chance2 =  rand() % 100;
            if(chance2 < 40){
                std::cout <<"===========================================\n";
                std::cout <<"==By a unbelivable luck the bear run away==\n";
                std::cout <<"===========================================\n\n\n";
                Sleep(2000);
                std::cout <<"===================================\n";
                std::cout <<"============You Survive!===========\n";
                std::cout <<"===================================\n";
                Sleep(3000);
                asking3 = false;
                return 0;
            }
            else{
                
                std::cout <<"===================================\n";
                std::cout <<"==The bear reach you and you die.==\n";
                std::cout <<"===================================\n";
                Sleep(1000);
                asking3 = false;
                return 0;
            }
            
        default:
            std::cout << "Invalid, try to type 'A','B' or 'C'\n";
            asking3 = true;
            break;
        }
        }  
    }
    if (userinput == 'C')
        {
        Sleep(1000);
        std::cout <<"A) Play Dead\n";
        std::cout <<"B) Scream.\n";
        std::cout <<"C) Walk back slowly.\n";
        
        char input4;
        
        bool asking4 = true;
        while (asking4)
        {
        std::cin >> input4;
        switch (input4)
        {
        case 'A':
            std::cout <<"You lay on the dirt.\n";
            Sleep(5000);
            std::cout <<"================================================\n";
            std::cout <<"========The bear trample and kill you.==========\n";
            std::cout <<"================================================\n";
            Sleep(1000);
            asking4 = false;
            return 0;
            break;
        case 'B':
            std::cout << "You scream a lot.\n";
            Sleep(3000);
            std::cout <<"=========================================\n";
            std::cout <<"==The bear realy don't like it and run.==\n";
            std::cout <<"=========================================\n";
            Sleep(1000);
            std::cout <<"===================================\n";
            std::cout <<"============You Survive!===========\n";
            std::cout <<"===================================\n";
            asking4 = false;
            Sleep(3000);
            return 0;
            break;
        case 'C':
            std::cout << "You go away slowy\n";
            Sleep(1000);
            int chance3;
            chance3 =  rand() % 100;
            if(chance3 < 50){
                std::cout <<"===================================\n";
                std::cout <<"===The bear gave up of eating you==\n";
                std::cout <<"===================================\n\n\n";
                Sleep(2000);
                std::cout <<"===================================\n";
                std::cout <<"============You Survive!===========\n";
                std::cout <<"===================================\n";
                Sleep(3000);
                asking4 = false;
                return 0;
            }
            else{
                
                std::cout <<"===================================\n";
                std::cout <<"==The bear reach you and you die.==\n";
                std::cout <<"===================================\n";
                Sleep(1000);
                asking4 = false;
                return 0;
            }
            
        default:
            std::cout << "Invalid, try to type 'A','B' or 'C'\n";
            asking4 = true;
            break;
        }
        }  
    }
}
1 Like

This isn’t supposed to compile, is it? Seems you are using placeholders, not actual syntax.

Love your effort, and I like your loop solutions using backup variables for safety nets. Your inventory set up is great. I did find I could break the loops, though, if a zero is entered, the next correct choice will not be lined up with the flow any more, inventory or story. So I guess a way to negate a zero selection would be ideal. Still, love the creativity here. Extremely well done! Quality writing too :grin:

Here it is my first adventure game! It is inspired on Harry Potter and it is also the first repository that I create! Hoping someone gives a try!

ferzsal’s adventure game

2 Likes

There are problems with my code but I can´t find them. Could anyone help me?

I think you may need to replace some of the quotation marks (both the single quotes for chars and double quotes for strings).

1 Like

The hard part was creating the story. It took me quite a bit of time to finish creating the story before actually creating the program.

Agree. But I could have the feeling that games programmer do. Creativity is the key in this exercise…

Your code has a lot of syntax errors. As I scanned your code, you had:

  1. Missing semi-colons after the end of a line.
  2. Missing end quotes (i.e., You tried to create a string by opening a quote but not ending it with another quote."
  3. Wrong characters in quoting strings (i.e. You used instead of ". It does not seem obvious, but you used a squiggly quote instead of a regular quote.
  4. You accidentally spelled Char instead of char.
  5. You accidentally wrote a semi-colon inside of a test expression.

Your code should be working write now: text-adventure.cpp. Check revisions to check where you went wrong. Just to be clear, I didn’t check the logic of your code. But I did try to run it and got to this ending message:

You finish the 2nd and the 3rd interviews with the ladies first. You conclude that all of them said the truth and none of them are the potential murder.

Last note: i++ and ++i works similarly for the for loops update values. But ++i sometimes works faster than i++. But i++ would never be faster than ++i. You can look it up on Google why.

Hi daniellabrador!
Thanks very much for revising my code! Well done! You´re right! There are a lot of mistakes. I revised my code and could improve the text too. I´ll leave it here just in case you are curious. Take care, buddy!

#include
int main ( ) {
std::cout << “Yesterday was Jeremy Travers´ sixtieth birthday. He had dinner at his country house with his wife Amanda, his daughter Barbara, his business partner Gordon Smith, and his secretary Claudia Simeone. Next morning, when Amanda Travers went to her husband´s bedroom she found him in bed… dead.\n”;
std::cout << “You, as an inspector, are called to the house the same day. When you arrive, Amanda, Barbara, Gordon and Claudia are waiting for you in the living room.\n”;
std::cout << “* * *\n”;
std::cout << “What do you do?”\n”;

char choice 1;

for ( int i = 0; i < 3; && choice1 != ‘A’ && choice1 != ‘B’ && choice1 != ‘C’; i++) {

	std::cout << “Enter A if you come in the room, summarize what had happened the night before and invite Mrs Travers to talk in the library.\n”;
	 std::cout<< “Enter B if you introduce yourself quietly to Barbara and asks her to tell the others to organize themselves;  you´re going to interview them in the library.\n”; 
	Std::cout<< “Enter C if you straight invite Claudia to go to the library.\n”;
	Std::cin>> choice1;

}
Switch (choice1) {

case ‘A’:
std::cout<< “ You interview Mrs. Travers about what happened the night before and asks if she loved Mr. Travers.\n”;
std::cout<< “Mrs. Travers says she went for a walk in the garden and after went to sleep. This morning she woke up and took him a cup of tea. She found him… dead. ‘No, I hated him’ – Mrs Travers replies about loving him or not.\n”;
break;

case ‘B’:
std::cout<< “You ask Barbara what she did the night before after dinner and if she had any problem with her father”;
std::cout<< “Barbara says she played cards with Gordon and went to bed. She didn´t listen anything in her father´s room. She says she didn´t have any problem with her father and starts to cry. ‘He was a perfect father’ – she says while crying\n”;
break;

case ‘C’:
std::cout<< “You ask Claudia Simeone what she did the night before and if she was in love Mr. Travers”;
std::cout<< “Claudia refuses to admit she had an affair with Mr. Travers but after being insisted she says she expected to marry him. She believed him when he said he would leave his wife. After being questioned if she killed him, she said no because she loved him.”;
break;

dafult:
std::cout<< “Sorry, you haven´t entered a valid choice\n”;
std::cout<< “Good-bye/n”;
return 0;
}
std::cout<< “After your first interview, you go back to the living room. Your stomach starts growling and you remember you didn´t have time for breakfast this morning. You think of interrupting the interviews and ask for a quick meal.”;
std::cout << * * *\n”;
std::cout<< “Do you tell the family about your problem and ask for a quick break so that you can have a quick meal?\n”;

char choice2;

for ( int i = 0; i < 3 && choice2 != ‘A’ && choice2 != ‘B’; i++) {

std::cout<< “Enter A if you ask for a break for food.\n”;
std::cout<< “Enter B if you decide to wait until the interviews are over.\n”;
std::cin<< choice2;
}
if (choice2 != ‘A’ && choice2 != ‘B’) {

std::cout<< “Sorry, you haven´t entered a valid choice.\n”;
std::cout<< “Good bye.\n”;
return 0;

} else if (choice2 == ‘B’) {
Std::cout<< “Your stomach rumbles audibly, during the interrogations.\n”;
Std::cout<< “You finish the 2nd and the 3rd interviews with the ladies first. You conclude that all of them said the truth and none of them are the potential murder.\n”;
Return 0;
}

Std::cout<< “You go to the kitchen and ask the butler for a sandwich with some orange juice. While eating, you talk to Watson (the butler) and feel a bit of angriness in his speech. The cook join the conversation and you discover Watson had some business with Mr. Travers.\n”
Std:cout<< “’He witnessed Mr. Travers life insurance and I´ve seen him talking with Barbara many times recently’ – said the cook conspiratorially.\n”;
Std:cout<< “’You traitor’ – shouted Watson. You owe me money and now want to get rid of me and your debts at the same time.\”;
Std::cout << * * *\n”;
Std::cout<< What do you do next?

Char choice 3;

For ( int i = 0; i < 3 && choice3 != ‘A’ && choice3 != ‘B’; i++) {

Std::cout<< “Enter A if you invite Watson for an interrogation in the libray.\n”;
Std::cout<< “Enter B if you trust your instinct with Barbara´s interview and decide to proceed with the interrogations you were doing, inviting Mr. Gordom to the library\n”;
Std::cin<< choice3;
}
If (choice3 != ‘A’ && choice3 != ‘B’) {

Std::cout<< “Sorry, you haven´t entered a valid choice.\n”;
Std::cout<< “Good bye.\n”;
Return 0;

} else if (choice3 == ‘B’) {

Std::cout<< “After your break, you go back to the living room and see a tiny red drop on Gordon´s sleeve. You invite him to the library and start asking what he did the night before.\n”;
Std::cout<< “He said he played cards with Barbara and when she went to bed, he had a glass of whisky. After he went to bed.\n”;
Std::cout<< “You say that Mr. Gordom and Mr. Travers were business partners. The business is good and now it is Gordom´s business.\n”;
Std::cout<< “Gordom said he had a conversation with Mr. Travers before dinner. ‘I said I was in love with Barbara, Mr. Gordom´s daughter and wanted to marry her’. Mr. Travers said Gordom just wanted her money and didn´t approve the marriage.\n”
Std::cout<< “’What about this red drop on your sleeve?’ – you ask curiously./n”
Std::cout<< “Gordom says that he was only going to speak in court now, with his lawyer./n”
Std::cout<< “THE END!/n”;
Return 0;
}
Std::cout<< “You leave the kitchen with Watson by your side. You both enter the library and you start asking him what he did the night before.\n”;
Std::cout<< “He explains and starts answering the accusations the cook had made. He said he was a bit worried with Barbara because she was in love with Gordom. ‘I considered her as a daughter, as I have been serving her since she was very little’. All the family trusted Watson and treated him as a member of the family.\n”;
Std::cout<< “You ask him what time he went to bed and if he had seen anything different the night before.\n”;
Std::cout<< “I went to bed after serving Gordom a glass of whisky – he replied. He saw Gordom going to Mr. Travers bedroom after the glass of whisky.\n”;
Std::cout<< “Based on his testimony and on Gordom´s dirty sleeve, you decide to take your investigations to the Criminal Justice.\n”;

Text-Adventure project
It is crazy how wild if-else branches get after a while… Let me know what you think!

#include

#include <stdlib.h>

int main()

{

std :: cout << " ---------------------------------\n";

std :: cout << " | Thien’s Text Adventure |\n";

std :: cout << " | A big fan of Harry Potter |\n";

std :: cout << " ---------------------------------\n";

std :: cout << " What is your favourite chapter in Harry Porter series?\n";

std :: cout << “1) Harry Potter and the Philosopher’s Stone\n”;

std :: cout << “2) Harry Potter and the Chamber of Secrets\n”;

std :: cout << “3) Harry Potter and the Prisoner of Azkaban\n”;

std :: cout << “4) Harry Potter and the Goblet of Fire\n”;

std :: cout << “5) Harry Potter and the Order of the Phoenix\n”;

std :: cout << “6) Harry Potter and the Half-Blood Prince\n”;

std :: cout << “7) Harry Potter and the Deathly Hallows\n”;

int user_input = 0;

std::cin >> user_input;

if (user_input == 1)

{

std :: cout << "Your favourite book is Harry Potter and the Philosopher's Stone\n";

}

else if (user_input == 2)

{

std :: cout << "Your favourite book is Harry Potter and the Chamber of Secrets\n";

}

else if (user_input == 3)

{

std :: cout << "Your favourite book is Harry Potter and the Prisoner of Azkaban\n";

}

else if (user_input == 4)

{

std :: cout << "Your favourite book is Harry Potter and the Goblet of Fire\n";

}

else if(user_input == 5)

{

std :: cout << "Your favourite book is Harry Potter and the Order of the Phoenix\n";

}

else if(user_input == 6)

{

std :: cout << "Your favourite book is Harry Potter and the Half-Blood Prince\n";

}

else if(user_input == 7)

{

std :: cout << "Your favourite book is Harry Potter and the Deathly Hallows\n";

}

return 0;

}

RogueByte
I dont know if I linked this properly or not, but I spun the idea into a mini roguelite type text adventure game. I’m happy with the outcome. Let me know if there are any bugs or typos that I missed. :slight_smile:

This is my first ever C++ Program and the first coding language I am currently teaching myself. I know it’s nothing amazing but I’m proud of this simple work. I wrote this inspired by Lost in Space (Netflix) and Interstellar (movie). Feel free to leave any feedback :slight_smile:

#include
#include

int main()
{
//keeps track of the player’s choice
int player_choice;
//keeps track of the player’s health
int player_health = 3;
char player_choice2;
char player_choice3;
std::string player_name;

std::cout << "Welcome survior, to DayZ! What is your name? " << "\n";
std::cin >> player_name;
std::cout << "Well, " << player_name << " you just spawned in to chernarus!" << "\n\n";
std::cout << player_name << ", your health is currently " << player_health << " out of 3\n";
std::cout << "Choose what you would like to do? But remember, your choices have consequences!" << "\n\n";
std::cout << "1. Go Looting / Base Build\n2. Go Hunting / Fishing\n3. Go Raid Bases / Camp Military Zones\n\n";
std::cin >> player_choice;

while (player_health !=0) {


    //player inputs invalid choice
    if (player_choice > 3 || player_choice < 0) {
        std::cout << "You have not picked a correct option... for that you lose 1/3 of your health points" << "\n";
        std::cout << player_name << " , your health is currently " << --player_health << "\n";
        std::cout << "Please pick again\n1. Go Looting / Base Build\n2. Go Hunting / Fishing\n3. Go Raid Bases / Camp Military Zones\n\n";
        std::cin >> player_choice;
        //return player_health;
        //return player_choice;
    }

    //branch 1
    else if (player_choice == 1) {

        std::cout << "What would like to do?\n\ta. Go Looting\n\tb. Build a Base\n\t";
        std::cin >> player_choice2;
        if (player_choice2 == 'a') {
            std::cout << "Would you like to go look for:\n\ta. Guns and Supplies\n\tb. Seeds and Garden Lime\n";
            std::cin >> player_choice3;
            if (player_choice3 == 'a') {

                std::cout << "While looting, you come accross some a gun with five bullets and some canned peaches and a jacket!\n\nYou manage to find a safe house to stay in to wait out the night\n";
                
            }
            else {

                std::cout << "While looting a green house you come accross some tomatoe seeds and some garden lime!\n\n";
                break;
            }
        }
        else if (player_choice2 == 'b') {
            std::cout << "Great choice! Would you like to\n\ta. Chop trees to get wood\n\tb. Crush rocks to get stone\n\t";
            std::cin >> player_choice3;
            if (player_choice3 == 'a') {

                std::cout << "You swing your axe and cut down many trees, these will make for fine walls and roofs!";
                
            }
            if (player_choice3 == 'b') {

                std::cout << "You swing your pick axe and break  many stones, these will make for a good flag pole base!";
                break;
            }
        }
    }
    //branch 2
    else if (player_choice == 2) {

        std::cout << "What would like to do?\n\ta. Go Hunting\n\tb. Go Fishing\n\t";
        std::cin >> player_choice2;
        if (player_choice2 == 'a') {
            std::cout << "Would you like to go hunting for:\n\ta. Pigs\n\tb. Deers\n";
            std::cin >> player_choice3;
            if (player_choice3 == 'a') {

                std::cout << "While hunting, you come accross some a wild pigs!\n\nYou manage to sneak up on one and strangle it with your bare hands!\n";
                
            }
            else {

                std::cout << "While walkiung thru the forest you spot some deer tracks and follow them... you spot a deer and take it out!\n\n";
               break;
            }
        }
        else if (player_choice2 == 'b') {
            std::cout << "You know of some water sources near by... would you like to fish for Bass or Trout?\n\ta. Fish for Bass\n\tb. Fish for Trout\n\t";
            std::cin >> player_choice3;
            if (player_choice3 == 'a') {

                std::cout << "You manage to find some worms to lure the bass... and then you stink one!!";
                
            }
            if (player_choice3 == 'b') {

                std::cout << "You manage to create a bone hook and bait a trout... after a few hours, you catch one!";
                break;
            }

        }
    }
    //branch 3
    else if (player_choice == 3) {

        std::cout << "What would like to do?\n\ta. Go Raid Bases\n\tb. Go Camp Military Zones\n\t";
        std::cin >> player_choice2;
        if (player_choice2 == 'a') {
            std::cout << "What would you like to raid bases with?:\n\ta. Hacksaw\n\tb. Homemade explosives\n";
            std::cin >> player_choice3;
            if (player_choice3 == 'a') {

                std::cout << "You find a simple barn base and use your hacksaw to break open into it after 30 mins of hacksawing\n\nYou manage to find some loot and some food!\n";
                
            }
            else {

                std::cout << "You manage to craft up a few homemade breaching charges! They make a lot of noise when they expode! They might have altered people or zombies near by...\n\n";
                break;
            }
        }
        else if (player_choice2 == 'b') {
            std::cout << "You know of some Military Zones up north... would you like to go to a checkpoint or airstrip?\n\ta. Checkpoint\n\tb. Airstrip\n\t";
            std::cin >> player_choice3;
            if (player_choice3 == 'a') {

                std::cout << "You manage to arrive at a military checkpoint and camp it for a few hours... you don't find anyone... but you get a few items and jacket\n";
                
            }
            if (player_choice3 == 'b') {

                std::cout << "You camp the barraks at the airstrip and spot someone within 10mins! You take a shot at them and wound them, and the zombies finish them off!\n";
                break;
            }

        }



    }

    if (player_health == 0) {
        std::cout << "Your health has reached zero and you have died!\n\n";
        std::cout << "\tTHANKS FOR PLAYING!\n\n";
        
    }


}
    
system("pause");

}

/* This game is a simple game that fouces on how to use conditional, logic, and loops. So, it is very easy idea where I will provide 3 options to let the user choose one of them in his mind and then I will ask questions and from his answer I will try to guess his choice. If I guess the right answer the game will end and I will win if I didn't get the right answer before the third question then I will lose. */ #include<iostream> int main(){ // The idea of the game std::cout<<"\t\tLets Play a simple game!\n"; std::cout<<"\t\t------------------------\n"; std::cout<<"\tWhich city would you like to visit most?\n"; std::cout<<"\tPlease choose one of the following cities:\n"; std::cout<<"\n\t1) Dubai.\t2) Cairo.\t3) Maldives.\n\n"; std::cout<<"\t\tNow let have some fun!\n\n"; std::cout<<"\nI will ask you two questions and if I get the right choice then I will win and if I didn't I will lose.\n"; std::cout<<"\n\n\t>>>>>> Let's start!!!\n\n\n\n"; int question =1; bool answer = false; while(answer == false){ switch(question){ case 1: int a1; std::cout<<"\tQ1) What do you love most?\n\n"; std::cout<<"1- Ancient.\t"; std::cout<<"2- Entertainment.\t"; std::cout<<"3- Relaxation.\n\n"; std::cout<<"Your answer is (1, 2, or 3): "; std::cin>>a1; switch(a1){ case 1: std::cout<<"\n\n\t\t----------------------\n"; std::cout<<"\n\t\t Your city is Cairo!\n\n"; std::cout<<"\t\t----------------------\n\n"; break; case 2: std::cout<<"\n\n\t\t----------------------\n"; std::cout<<"\n\t\t Your city is Dubai!\n\n"; std::cout<<"\t\t----------------------\n\n"; break; case 3: std::cout<<"\n\n\t\t----------------------\n"; std::cout<<"\n\t\t Your city is Maldives!\n\n"; std::cout<<"\t\t----------------------\n\n"; break; default: std::cout<<"\t\tNo right choice; exit and reopen the game!\n\n"; } char end1; std::cout<<"Is this right?\t"; std::cout<<"Y / N? \t"; std::cin>>end1; if(end1 == 'Y'){ std::cout<<"\n\n\tI won!!!\n\n"; answer = true; } else{ std::cout<<"\n\nLet's try again with a diiferent question!\n\n\n"; question++; } break; case 2: char a2; std::cout<<"\tQ2) Do you love shopping?\n\n"; std::cout<<"\t1- Yes.\t\t"; std::cout<<"2- No.\n\n"; std::cout<<"Your answer is (Y / N):\t"; std::cin>>a2; switch(a2){ case 'Y': std::cout<<"\n\n\t\t----------------------\n"; std::cout<<"\n\t\t Your city is Dubai!\n\n"; std::cout<<"\t\t----------------------\n\n"; break; case 'N': std::cout<<"\n\n\t\t----------------------\n"; std::cout<<"\n\t\t Your city is Maldives!\n\n"; std::cout<<"\t\t----------------------\n\n"; break; default: std::cout<<"\t\tNo right choice; exit and reopen the game!\n\n"; } char end2; std::cout<<"Is this right?\t"; std::cout<<"Y / N? \t"; std::cin>>end2; if(end2 == 'Y'){ std::cout<<"\n\n\tI won!!!\n\n"; } else{ std::cout<<"\n\n\tI lost the game!\n"; } answer = true; break; } } std::cout<<"******End of the game!******\n\n"; return 0; }

Anybody else have the problem with “while” loops and the or “||” logical operator not working on this project?

If I used a “while” loop, the website crashed and wouldn’t even save it. This is before I even tried to compile it.

Regarding the || operator, as I was trying to troubleshoot, I used this bit of code inside main()

int x;
 for (int i=0; i<3; i++) {
  if (x != 1 || x != 2 ) {
    std::cout << "3 chances to guess my numbers";
    std::cin >> x;
  }  
}

The loop would repeat 3 times regardless of what numbers I entered. Even if I entered a 1 or 2. If I took out the conditional statement “|| x != 2”, and guessed 1, the loop terminated properly.

I did my game based on the first Harry Potter book with a small amount of creative license! Most complicated program I’ve created so far, and pretty pleased with how it went!

https://github.com/toothless13/TEXT-ADVENTURE-STARTING