Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please Help! using C++, Thanks! Using Nested if and if…else Statements: 1a. Writ

ID: 3697316 • Letter: P

Question

Please Help! using C++, Thanks!

Using Nested if and if…else Statements:

1a. Write what the following statements display as output after the program executes. int temperature = 78; int month = 6; string name = “Pat Boone”; if ( temperature >= 70 && month >=6) cout << “Wear white shoes. ”; else if (name == “Pat Boone”) cout << “Wear white shoes. ”; else cout << “Wear black shoes. ”;

1b. What is the output of the program in Exercise 1a when temperature = 70, month = 5, and name = “Pat Boone”?

1c. What is the output of the program in Exercise 1a when temperature = 60, month = 5, and name = “Pat Boone”?

1d. What is the output of the program in Exercise 1a when temperature = 60, month = 5, and name = “Your name”?

Explanation / Answer

1a. Write what the following statements display as output after the program executes.

int temperature = 78;
int month = 6;
string name = "Pat Boone";
if ( temperature >= 70 && month >=6)    //temperature greater than or equal to 70 condition satisfies. month >= 6 also satisfies.
cout << "Wear white shoes. ";    //So, this statement will be executed.
else if (name == "Pat Boone")   
cout << "Wear white shoes. ";  
else
cout << "Wear black shoes. ";

So, the output of the above code is: Wear white shoes.

1b. What is the output of the program in Exercise 1a when temperature = 70, month = 5, and name = “Pat Boone”?

int temperature = 70;
int month = 5;
string name = "Pat Boone";
if ( temperature >= 70 && month >=6)    //temperature greater than or equal to 70 condition satisfies. month >= 6 condition fails.
cout << "Wear white shoes. ";   
else if (name == "Pat Boone")        //name == Pat Boone condition satisfies.  
cout << "Wear white shoes. ";       //So, this statement will be executed.
else
cout << "Wear black shoes. ";

So, the output of the above code is: Wear white shoes.

1c. What is the output of the program in Exercise 1a when temperature = 60, month = 5, and name = “Pat Boone”?

int temperature = 60;
int month = 5;
string name = "Pat Boone";
if ( temperature >= 70 && month >=6)    //temperature greater than or equal to 70 condition fails.
cout << "Wear white shoes. ";   
else if (name == "Pat Boone")        //name == Pat Boone condition satisfies.  
cout << "Wear white shoes. ";       //So, this statement will be executed.
else
cout << "Wear black shoes. ";

So, the output of the above code is: Wear white shoes.

1d. What is the output of the program in Exercise 1a when temperature = 60, month = 5, and name = “Your name”?

int temperature = 60;
int month = 5;
string name = "Hershley";
if ( temperature >= 70 && month >=6)    //temperature greater than or equal to 70 condition fails.
cout << "Wear white shoes. ";   
else if (name == "Pat Boone")        //name == Pat Boone condition also fails.  
cout << "Wear white shoes. ";      
else
cout << "Wear black shoes. ";        //So obviously, this statement will be executed.

So, the output of the above code is: Wear black shoes.