Sovi.AI - AI Math Tutor

Scan to solve math questions

QUESTION IMAGE

organize the lines of code to create an if - else statement that output…

Question

organize the lines of code to create an if - else statement that outputs goodbye, ending with a newline, if userstring is quit. otherwise, output hello, ending with a newline. note: not all lines of code on the left will be used in the final solution. how to use this tool unused cout << \goodbye\; cout << \goodbye\ << endl; else { else if { cout << \hello\ << endl; cout << \hello\; } if (userstring == \quit\) { if (userstring = \quit\) { } main.cpp #include <iostream> #include <string> using namespace std; int main() { string userstring; cin >> userstring; return 0; }

Explanation:

Step1: Add condition check block

if (userString == "Quit") {

Step2: Add goodbye output with newline

    cout << "Goodbye" << endl;

Step3: Add else block

} else {

Step4: Add hello output with newline

    cout << "Hello" << endl;

Step5: Close else block

}

Answer:

The completed main.cpp code is:

#include <iostream>
#include <string>
using namespace std;

int main() {
    string userString;

    cin >> userString;

    if (userString == "Quit") {
        cout << "Goodbye" << endl;
    } else {
        cout << "Hello" << endl;
    }

    return 0;
}