Boolean function not working

So here it is I am learning C++ from scratch, things seemed to go alright till now but now i have decided to use Boolean function to check user input and its not working as it should can someone please check the code below and reply.
Thanks in advance

-->> Function prototype

bool check(double);

-->> Code in main

for(i=0;i<size;i++)
{
double temp=0;
cout<<"Please enter sales for "<< month[i]<< ":- ";
cin>>sales[i];
while (check(sales[i]))
{
cout<< "Invalid inpit. Please enter again:- ";
cin>>sales[i];
}
}


-->> code in function

bool check(double temp1)
{
if ((temp1<1)&&(temp1>25000))
return true;
return false;
}
if ((temp1<1)&&(temp1>25000))

temp1 cannot possibly be both less than 1 AND greater than 25000.

Did you mean to use >= 1 and <= 25000 ?
Last edited on
Look at the logic, that function can never return true.

If temp1 is less than 1 and temp1 is greater than 25000. There isn't a number that can satisfy that.

Are you trying to make sure the number is between that range?

1
2
if( temp1 >= 1 && temp1 <= 25000 )
   return true;
Last edited on
((temp1<1)&&(temp1>25000))
lol i have no idea what kind of number would comply with this condition.

smaller than 1 and bigger than 25000 at the same time?
Opppsss...
looks like I was thinking as headless chicken....
i was so stressed couldnt think of it...
thanks
Easily done. :-)
Topic archived. No new replies allowed.