void Numdays::setHours(int h)
{
hours = h;
days = h / 8;
}
void Numdays::setDays( double d)
{
if (hours >= 8)
{
days += 1;
}
}
int Numdays::getHours()
{
return hours;
}
double Numdays::getDays()
{
return days;
}
int main()
{
Numdays d(0);
int work;
cout << "Please type in a certain amount of hours to convert how much work in days is it:" << endl;
cin >> work;
d.setHours(work);
d.setDays(work);
cout << " THe number of hours you put is" << d.getHours() << endl;
cout << " That would mean you work about " << d.getDays() << " days " << endl;
system("pause");
return 0;
}
The out put I am getting is:
EX:
Please type in a certain amount of hours to convert how much work in days is it:
8
The number of hours you put is 8
That would mean you work about 2 days
Press any key to continue . . .
EX:
Please type in a certain amount of hours to convert how much work in days is it:
12
THe number of hours you put is 12
That would mean you work about 2 days
Press any key to continue . . .
EX:
Please type in a certain amount of hours to convert how much work in days is it:
16
THe number of hours you put is 16
That would mean you work about 3 days
Press any key to continue . . .
can someone help me on why It has 1+ more day than it should be.
Also if someone can help me figure how it can give me answer like 1.50 hours.
Example How i put in 12 hours that is about 1.5 days of work
Can someone explain how I can make my class program give me this output.
void Numdays::setDays( double d)
{
if (hours >= 8)
{
days += 1;
}
So long as you've already set hours to 8 or greater, then no matter what value you pass to this function you'll be incrementing days. Try entering 5 hours and you'll see what I mean.
Try basing you condition on the value passed in instead.
Also your pre-decrement and pre-increment operators calculate wrong. Instead of calculating days from original hours decremented or incremented by one, you actually calculate it on original hours decremented or incremented by 2.
So i fixed a little bit of the program and it still shows that 8 hours consist of 2 days. I was able to get to to say if I work 12 hours it now shows 2.5 days. But its still a day ahead of what it should be