Question Regarding Boolean Please

Dec 27, 2017
Reaction score

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;
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