expand icon
book C++ Programs to Accompany Programming Logic and Design 8th Edition by Jo Ann Smith cover

C++ Programs to Accompany Programming Logic and Design 8th Edition by Jo Ann Smith

Edition 8ISBN: 978-1285867410
book C++ Programs to Accompany Programming Logic and Design 8th Edition by Jo Ann Smith cover

C++ Programs to Accompany Programming Logic and Design 8th Edition by Jo Ann Smith

Edition 8ISBN: 978-1285867410
Exercise 11
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 from this program when
if(drink == "Coke" || drink == "Pepsi")
is changed to
if(drink == "Coke" || drink == "Pepsi" || drink == "coke" || drink == "pepsi")
and the customer's name is Chas Matson, and the drink is coke? What does this change allow a user to enter?
Explanation
Verified
like image
like image

OR Logic ( || ):
The OR Logic (||) help...

close menu
C++ Programs to Accompany Programming Logic and Design 8th Edition by Jo Ann Smith
cross icon