
C++ Programs to Accompany Programming Logic and Design 8th Edition by Jo Ann Smith
Edition 8ISBN: 978-1285867410
C++ Programs to Accompany Programming Logic and Design 8th Edition by Jo Ann Smith
Edition 8ISBN: 978-1285867410 Exercise 7
Making Multiple Comparisons in Decision Statements
In this exercise, you use what you have learned about OR logic to study a complete C++ program that uses OR logic in a decision statement. This program was written for a marketing research firm that wants to determine if a customer prefers Coke or Pepsi over some other drink. Take a few minutes to study the code that follows, and then answer Questions.
// CokeOrPepsi.cpp - This program determines if a customer// prefers to drink Coke or Pepsi or some other drink.#include #include using namespace std;int main(){string customerFirstName; // Customer's first namestring customerLastName; // Customer's last namestring drink = ""; // Customer's favorite drinkcout ? "Enter customer's first name: ";cin ? customerFirstName;cout ? "Enter customer's last name: ";cin ? customerLastName;cout ? "Enter customer's drink preference: ";cin ? drink;if(drink == "Coke" || drink == "Pepsi"){cout ? "Customer First Name: " ? customerFirstName? endl;cout ? "Customer Last Name: " ? customerLastName? endl;cout ? "Drink: " ? drink ? endl;}elsecout ? customerFirstName ? " " ? customerLastName? " does not prefer Coke or Pepsi." ? endl;return 0;}
What is the exact output when this program executes if the customer's name is Chas Matson and the drink is Pepsi?
In this exercise, you use what you have learned about OR logic to study a complete C++ program that uses OR logic in a decision statement. This program was written for a marketing research firm that wants to determine if a customer prefers Coke or Pepsi over some other drink. Take a few minutes to study the code that follows, and then answer Questions.
// CokeOrPepsi.cpp - This program determines if a customer// prefers to drink Coke or Pepsi or some other drink.#include #include using namespace std;int main(){string customerFirstName; // Customer's first namestring customerLastName; // Customer's last namestring drink = ""; // Customer's favorite drinkcout ? "Enter customer's first name: ";cin ? customerFirstName;cout ? "Enter customer's last name: ";cin ? customerLastName;cout ? "Enter customer's drink preference: ";cin ? drink;if(drink == "Coke" || drink == "Pepsi"){cout ? "Customer First Name: " ? customerFirstName? endl;cout ? "Customer Last Name: " ? customerLastName? endl;cout ? "Drink: " ? drink ? endl;}elsecout ? customerFirstName ? " " ? customerLastName? " does not prefer Coke or Pepsi." ? endl;return 0;}
What is the exact output when this program executes if the customer's name is Chas Matson and the drink is Pepsi?
Explanation
OR Logic ( || ):
The OR Logic (||) help...
C++ Programs to Accompany Programming Logic and Design 8th Edition by Jo Ann Smith
Why don’t you like this exercise?
Other Minimum 8 character and maximum 255 character
Character 255