### If and else statements

This is my first post on this forum and I'm excited to join! This is a homework questions so I'm not looking for a solution, but I have an issue with a "if" and "else" problem. I just need help with the formatting. Here is the problem and my coding is below.

************************************************************
"You're working undercover for MI6. Whilst infiltrating a Svenborgian military outpost, you arrive at the door to the base and notice that there is an explosive rigged to the door. Before opening the door, you must determine if the device is armed or not, and whether you should open the door. From your time in BombSquad 101, you remember that a device like this will only be armed if all three switches are in the same position.

Input

You will be given strings (either "Up" or "Down") that correspond to the positions of the three switches on the device.

Output

If the device is armed, output "Device is armed. Do not open!"

if the device is not armed, output "Device is not armed. You may proceed."
*********************************************************

 ``123456789101112131415161718192021222324252627282930313233`` `````` #include #include using namespace std; int main() { cout << "Please enter the directions of the switches."; string switch1, switch2, switch3; cin >> switch1 >> switch2 >> switch3; //If the device is armed, output "Device is armed. Do not open!" //if the device is not armed, output "Device is not armed. You may proceed." if (switch1 == "Up", switch2 == "Up", switch3 == "Up") { cout << "Device is not armed. You may proceed." << endl; } if (switch2 == "Down", switch2 == "Down", switch3 == "Down") { cout << "Device is not armed. You may proceed." << endl; } else { cout << "Device is armed. Do not open!" << endl; } system("pause"); return 0; }``````

So the output will display "Device is not armed. You may proceed." Even when it isn't "Up Up Up" or "Down Down Down". I just need help with the formatting possibly of the if and else statements or I might be doing this totally wrong. I appreciate any help offered. This isn't due for about 2 weeks so no rush on trying to get help. If I totally messed up just let me know and I will try re-reading the chapter for my class again :)
&& is the logical and operator. So `if(switch1 == "Up" && switch2 == "Up" && switch3 == "Up")` would work.

Edit: Oh and welcome. :D
Last edited on
Thanks so much Mats I got it figured out now! Much appreciated.
Topic archived. No new replies allowed.