// Lab Homework 9
// Logical Operator AND and OR
// Demonstrate how to use a logical operator
// with a Boolean expression.
#include <iostream>
#include <cctype> // for tolower()
using namespace std;
int main()
{
/* Create a program that produces the Sample Output
shown at the bottom.
You MUST:
- Output all of the lines show below in the Sample
Output - spacing, spelling, punctuation, etc. must be exact
matches
NOTE: There are FOUR different runs of the program
shown - do not have your program do all four at once
- Declare variables and/or constants appropriately,
name them according to standards
(points will be deducted for poor names), and be sure
to use appropriate data types
- You MUST use a compound conditional (you decide
whether you need && or ||), only ONE if and ONE else are
allowed
*/
// <write your solution code below this
comment>
cout << endl << endl;
return 0;
}
/* Sample interaction and output:
Run the program once - the user enters y and y
==========================================
Answer the following questions
with either yes or no (y or n):
Are you a student? y
Are you 65 or older? y
Congratulations!
You qualify for discounted movie tickets.
Press any key to continue . . .
Run the program a second time - the user enters y and N
==========================================
Answer the following questions
with either yes or no (y or n):
Are you a student? y
Are you 65 or older? N
Congratulations!
You qualify for discounted movie tickets.
Press any key to continue . . .
Run the program a third time - the user enters N and y
==========================================
Answer the following questions
with either yes or no (y or n):
Are you a student? N
Are you 65 or older? y
Congratulations!
You qualify for discounted movie tickets.
Press any key to continue . . .
Run the program a fourth time - the user enters n and N
==========================================
Answer the following questions
with either yes or no (y or n):
Are you a student? n
Are you 65 or older? N
Sorry.
You must be a student or a senior citizen to receive discounted
movie tickets.
Press any key to continue . . .
*/
// Lab Homework 9 // Logical Operator AND and OR // Demonstrate how to use a logical operator // with a Boolean expression. #include <iostream> #include <cctype> // for tolower() using namespace std; int main() { /* Create a program that produces the Sample Output shown at the bottom. You MUST: - Output all of the lines show below in the Sample Output - spacing, spelling, punctuation, etc. must be exact matches NOTE: There are FOUR different runs of the program shown - do not have your program do all four at once - Declare variables and/or constants appropriately, name them according to standards (points will be deducted for poor names), and be sure to use appropriate data types - You MUST use a compound conditional (you decide whether you need && or ||), only ONE if and ONE else are allowed */ // <write your solution code below this comment> char student, senior_citizen; cout << "Answer the following questions" << endl; cout << "with either yes or no (y or n):" << endl; cout << "Are you a student? "; cin >> student; cout << "Are you 65 or older? "; cin >> senior_citizen; student = tolower(student); senior_citizen = tolower(senior_citizen); if (student == 'y' || senior_citizen == 'y') { cout << "Congratulations!" << endl; cout << "You qualify for discounted movie tickets." << endl; } else { cout << "Sorry." << endl; cout << "You must be a student or a senior citizen to receive discounted movie tickets." << endl; } cout << endl << endl; return 0; }
Get Answers For Free
Most questions answered within 1 hours.