case 'Y' && 'y':
&& looks at expressions to the left and to the right of it. If both are nonzero, && returns 1 (true).
'Y' and 'y' are both nonzero.
Therefore
'Y' && 'y'
evaluates to
1
. So
case 'Y' && 'y':
is the same as
case 1:
Notice that
case 'N' && 'n':
is ALSO the same as
case 1:
, so you have two cases that are exactly the same, and
neither of them check to see if the user pressed Y or N.
What you probably wanted was this:
1 2
|
case 'Y': case 'y': cout << "Here you go."; break; // don't forget to break;
case 'N': case 'n': cout << "Goodbye then."; break;
|
But note that you don't even need to check for lowercase 'y' or 'n' becaues you're calling toupper. (although you're calling it incorrectly)
==================
As for your toupper problem:
|
switch(toupper(char& ask))
|
When calling functions, you do not give the type. You just give the parameters. The correct way to call toupper here would be like so:
|
switch(toupper(ask)) // note: no 'char&'
|
Other notes:
- you should use cout instead of printf. printf isn't typesafe
- 'question' should take 'ask' by value, not by reference. (ie:
void question(char ask)
is better than
void question(char& ask)
).