So I have a question about bool variables.
This is a program which checks whether the due is payed on time and if it is not, it is multiplied by 1.10.
#include <iostream>
using namespace std;
int main()
{
float Dues;
cout<<"Enter ammount: \n";
cin>>Dues;
cout<<"On time? (y/n)";
char yn;
cin>>yn;
bool Overdue = yn !="y"; //TRUE (1) if it is late, FALSE (0) if it is on time
float AmountDue;
AmountDue = Overdue ? Dues*1.10 : Dues;
cout<<"Ammount due: ";
cout<<<<AmountDue;
return 0;
}
I don’t undestand the logic of the bool
We have
bool Overdue = yn !="y";
Now this is my understaning of the logic of the bool and it is NOT right
If “n” is entered => N is NOT Y which is CORRECT therefore the bool is true => 1
If “y” is entered => Y is NOT Y which is WRONG, therefore fasle => 0
But it is actually the other way around and I can’t explain it logically to myself.
On what logic is based bool Overdue = yn !="y"; ?
In addition to jrok’s answer the problem you are encountering is that you assume that lowercase and uppercase characters are the same thing. They are NOT. ‘y’ and ‘Y’ are two different characters. Same thing for ‘n’ and ‘N’.
You write:
No. ‘n’ is not ‘y’.
It’s CORRECT. ‘y’ is NOT ‘Y’.
Try this instead: