lundi 3 août 2020

If Statement Issues [C++]

So everything works, you can do the first cin for the choice string, but after that, the cin for choice2 in the if statement doesn't work. The program will just end. I am very new to C++ and I really need some pointers to get more fluent. Please help me with this.

#include <iostream>
using namespace std;

int main() {
   
    string Choice;
    string Choice2;
    string Choice3;
    string Choice4;
   
    cout << "Welcome to the Police Adventure game! A text based adventure game where you can take on the life of a police officer choosing the best choice for the current situation!" << endl;
    cout <<  "You start your career and pull someone over. Please type either A, or B. Do you (A)Approach cautiously and ask them for their ID, or do you (B)Approach quickly with your gun drawn in hopes that they are wanted." << endl;
   
    cin >> Choice;
   
    if (Choice == "A") {
       
        cout << "The driver hands their ID to you, and you head back to your vehicle to run it through the computer." << endl;
        cout << "Please type either A, or B. Do you (A)Run the ID, or do you (B)Pretend to run the ID." << endl;
        cin >> Choice2;
       
    }
    else if (Choice2 == "A") {
       
        cout << "The driver comes back as a wanted felon with one charge of homicide." << endl;
        cout << "Please type either A, or B. Do you (A)Order them out of the vehicle at gunpoint, or do you (B)Pretend to not notice it and let them go." << endl;
        cin >> Choice3;
       
    }
    else if (Choice2 == "B") {
       
        cout << "You pretend to run the ID, and let the suspect go. It turns out that they were wanted for homicide, and killed an officer right before he was caught." << endl;
        cout << "GAME OVER" << endl;
       
    }
    else if (Choice3 == "A") {
       
        cout << "The driver tells you he has a gun, and throws it out of the window. The driver then proceeds to slowly exit the vehicle." << endl;
        cout << "Please type either A, or B. Do you (A)Arrest them, or do you (B)Shoot them." << endl;
        cin >> Choice4;
   
    }
    else if (Choice4 == "A") {
       
        cout << "You arrested the driver, and got a promotion." << endl;
        cout << "YOU WIN" << endl;
       
    }
    else if (Choice4 == "B") {
       
        cout << "You shot the driver dead, and you were fired and arrested for shooting a non-deadly suspect." << endl;
        cout << "GAME OVER" << endl;
       
    }
    if (Choice == "B") {
       
        cout << "The driver grabs a concealed weapon and opens fire killing you and one civilian in the crossfire." << endl;
        cout << "GAME OVER" << endl;
       
    }
}

Aucun commentaire:

Enregistrer un commentaire