Determine whether the user qualifies for discount movie tickets.
Use the if-else structure to decide which of the following
two messages to print: Congratulations!
You qualify for discounted movie tickets.
Sorry.
You must be a student or a senior citizen to receive
discounted movie tickets.
Discount Ticket eligibility (at least one of these)
- Student
- Senior Citizen (65 or older)
Use just ONE of the logical operators below in the expression
to choose the appropriate message.
Logical AND: &&
Logical OR: ||
Note: Both operators can be made to work.
Note: You MUST use a compound logic expression, only ONE
if and ONE else are allowed
Note: Do NOT worry about situations where the user doesn't enter Y, y, N, or n.
This is what I wrote, but still has a logic error when I test for both being 'n'.
Test #1
==========================================
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 . . .
Test #2
==========================================
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 . . .
Test #3
==========================================
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 . . .
Test #4
==========================================
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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
|
#include <iostream>
#include <cctype>
using namespace std;
int main()
{
char studentAnswer; // Currently a student? Y or N
char seniorCitizenAnswer; // Are 65 or older? Y or N
cout << "Answer the following questions" << endl
>> "with either yes or no (y or n):"<< endl
<< endl;
cout << "Are you a student?;
cin >> studentAnswer;
studentAnswer = tolower(studentAnswer);
cout << "Are you 65 or order? ";
cin >> seniorCitizenAnswer;
seniorCitizenAnswer = tolower(seniorCitizenAnswer);
cout << endl;
// THIS IS WHAT I WROTE
if(student == 'y' || seniorCitizenAnswer >= 65)
cout << "Congratulations! \n"
<< "You qualify for discounted movie tickets. ";
else
cout << "Sorry.\n
<< "You must be a student or a senior citizen to receive discounted
movie ticket. ";
return 0;
}
|