Hi,
I have a program which needs to accept a date,
it can only accept under 30 days, and the entry has to be over 0

My problem is that it accepts anything, it doesnt make sense because i have used the exact layout on other bits of code which work perfectly,

do {  
     cout << "Please enter day: ";
     cin >> day;
     system("cls");
     }
     while ((day >= 0) & (day <= 30));
     cout << "Day Accepted";
     Sleep(1000);
     system("cls");

All it does is go straight to day accepted no matter what,
i have tried using { on the while part,
i am using devcpp

you know that in c++ you cant use " & " alone for the "and" purpose right?

try " && " thats the "and" or try " || "

you know that in c++ you cant use " & " alone for the "and" purpose right?

You can (with proper care), but it's not short circuited and tends to be confusing. I don't know anyone who would let & instead of && slide during a code review.

sorry my bad :) i learn by my self and didn't knew that & could be used for "and" too.

Hi, Solved the problem with ||

I did usually use && and had tried with no avail using that,
It was confusing because some of my other loops work with just &

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.