Question Regarding Boolean Please

Joined
Dec 27, 2017
Messages
2
Reaction score
0
Hello,

I just started teaching myself C++ from a very old book and I was hoping somebody could please help me out. I haven't gotten into functions yet.


#include "stdafx.h"
#include <iostream>
using namespace std;


int main()
{
float Dues;
float AmountDue;

cout << "Enter the amount due: ";
cin >> Dues;


cout << "Are the dues paid on time? (y/n) ";
char yn;
cin >> yn;


bool Overdue; //True if overdue, false if on time
Overdue = yn != 'y';

if (Overdue)
AmountDue = Dues * 1.10;
else
AmountDue = Dues;


cout << AmountDue;
cout << "\n\n";


return 0;
}


I am very confused as to what's going on with the boolean variable Overdue, specifically how the heck do I know if it's set to true or false!?!

First, I know that we have to assign Overdue to the variable yn:

Overdue = yn

Then this next part really confuses me because at this point Overdue can equal either a y or a n depending on the person's input.

And now it's saying:

!= 'y'

So overdue can equal y or n, BUT it doesn't equal (!=) y. So to me this looks like if overdue is set to n that means its now set to true because it cannot equal y (because of this: !=)?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,790
Messages
2,569,637
Members
45,346
Latest member
EstebanCoa

Latest Threads

Top