Click here to Skip to main content
15,887,135 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I wrote this code for my assignment but i don't seem to get any message at all after i put 'y' or 'n' in my output.

What I have tried:

C++
if ((studentAnswer == 'Y') || (seniorCitizenAnswer == 'Y'))
	{
		cout << "Congratulations!" << endl;
		cout << "You qualify for discounted movie tickets." << endl;
	}
	else if ((studentAnswer == 'N') && (seniorCitizenAnswer == 'N'))
	{
		cout << "Sorry." << endl;
		cout << "You must be a student or a senior citizen to receive discounted movie tickets." << endl;
	}

	cout << endl << endl;

	return 0;
Posted
Updated 13-Sep-17 21:26pm
v2
Comments
ArunRajendra 14-Sep-17 0:15am    
C++ is case sensitive. Are you using "Y" or "y"?

1 solution

You check some user input against 'Y' and 'N' but user input can be 'y' or 'n', in which case your test fail.
Solutions:
- you need to force user to input uppercase.
- add a check for 'y' and 'n' too.
- test with uppercase if user input; by using the toupper function.

If user input can only be 'Y' and 'N', your code can be simplified because if iris not one, it is automatically the other.
C++
if ((studentAnswer == 'Y') || (seniorCitizenAnswer == 'Y'))
{
}
else if ((studentAnswer == 'N') && (seniorCitizenAnswer == 'N'))
{
}
 
Share this answer
 
Comments
CPallini 14-Sep-17 3:27am    
5.
Patrice T 14-Sep-17 3:36am    
Thank you

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900