Can anyone tell me where I'm going wrong? When I run the code, only the first portion can be answered by yes or no, then it puts out the next two outcomes. help please! i'm new to coding, so forgive me.
#include <iostream>
#include <string>
using namespace std;
int main()
{
string name;
char choice;
cout << "A sailor walks onto the flightline and sees an F/A-18 Super Hornet on fire." << endl;
cout << "They then spring jump into action and run to the aircraft to help. They" << endl;
cout << "grab the first fire suppresion cart they see but it does not work." << endl;
cout << "The sailor looks into the cockpit and sees a pilot inside." << endl;
cout << "Does the sailor stay and help the pilot? Yes or No?" << endl;
cin >> choice;
cout << "" << endl;
if (choice == 'Yes')
{
cout << "The sailor climbs up the burning aircraft's ladder and tries to get the pilot to" << endl;
cout << "open the canopy but he sees the pilot has become unconscious due to smoke inhalation." << endl;
cout << "The sailor can break open the canopy or use the speed handle to manually open" << endl;
cout << "it? Does the sailor use the speed handle?" << endl;
cin >> choice;
cout << "" << endl;
if (choice == 'Yes')
{
cout << "The canopy is fully opened by the fast efforts of the sailor. The pilot" << endl;
cout << "is then helped out of the cockpit and down onto the ground away from the" << endl;
cout << "flames and smoke. The sailor then jumps into the cockpit and performs the" << endl;
cout << "engine shut down emergency procedures and activation of the fire suppresion system" << endl;
cout << "of the environmental control system. All is well." << endl;
}
else
{
cout << "The sailor beat down on the canopy to break it but the fiberglass merely" << endl;
cout << "cracked. They tried again but was only able to break a small hole in which" << endl;
cout << "the smoke could escape. The sailor could have made a better choice." << endl;
exit(0);
}
}
else
{
cout << "The sailor ran away from the burning aircraft, up the stairs, and into" << endl;
cout << "maintenance control. They yelled and pleaded with the chiefs and officers to" << endl;
cout << "call for help. The sailor then saw the panic in the control room. Could the" << endl;
cout << "sailor help more? Yes or No?" << endl;
cin >> choice;
cout << "" << endl;
if (choice == 'Yes')
{
cout << "The sailor then grabbed a telephone and called the base's fire fighting department." << endl;
cout << "They went back outside to find other sailors to help fight the aircraft fire." << endl;
}
else
{
cout << "The sailor sat back and let the chiefs and officers take care of the burning" << endl;
cout << "aircraft. After all, what more could a lower ranking sailor do? This was not" << endl;
cout << "the best outcome for the poor pilot in the smokey cockpit as he needed a hero" << endl;
cout << "to save him from an unnessary death." << endl;
exit(0);
}
}
return 0;
}
Your issue is that the variable choice is being tasked with inputting 3 characters, you need to convert char choice;
to string choice;
and convert all if (choice == 'Yes')
to if (choice == "Yes")
in order for the variable choice to process.
Or if you prefer to use 'char' over 'string', you can convert all if (choice == 'Yes')
to if (choice == 'Y')
Hope this helps!
EDIT: string uses double quotes (") while char uses single quotes (').