I want to assign 60minutes above duration of call = 15% discount
within the time of 1800pm(6:00pm) before 0800am(8:00am) = 50% discount
but if the caller called 60minutes above but within the time of
801am(8:01am) before 1800pm(6:00pm) he/she won't have the 50% discount.
So far this is the code I tried but it doesn't seem to work!
CODE:
if (duration>=60 || timestart>=1800 && timestart<=800 || endcall>=1800 && endcall<=800)
{ duration=duration*.40; /* .40 is the rate per minute */
printf("\nGross Cost: %.2f",duration);
duration=duration*.04; /* .04(4%)is the tax */
printf("\nTax Cost: %.2f",duration);
a=duration; /* Nevermind the variable pls */
b=duration*.15; /* 15% discount for more than 1hr call */
a/=2. /* 50% discount */
a=(a-b)+tax /* Gross minus discount plus the tax */
printf("\nNet Cost: %.2f",a); }
*NOTE: In else if statement, there won't be 50% discount because of the time schedule*
else if (duration>=60 || timestart<=1799 && timestart>=801 || endcall<=1799 && endcall>=801)
{ duration=duration*.04;
c=duration; /* Nevermind the variable pls */
d=duration*.15; /* 15% discount for more than 1hr call */
c=(c-d)+tax /* Gross minus discount plus the tax */
printf("\nNet Cost: %.2f",c); }
Ok so the problem is within the time range, if i put on start time 1800 then end time 1861 the output is:
Duration of call : 61minutes
Gross Cost:24.40
Tax: 0.98
Net Cost: 9.52
That one is fine BUT
If i put the start time to 801 and end time to 902
the output is:
Duration of call : 61minutes
Gross Cost:24.40
Tax: 0.98
Net Cost: 9.52
It's like it's not reading the else if statement that I put. I'm not sure if its because of the "(duration>=60)" or something else? please correct my coding! thx!!!!
The problem is that the computer expects continuous numbers while time isn't.
The next thing is that you do only something when duration>=60. What happens if it is not?
The solution is simplify and better names for the variables:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
...
if(duration < 60)
cost_factor = 1;
else
cost_factor = .15;
...
// if(timestart<=1799 && timestart>=801 || endcall<=1799 && endcall>=801) // Here we have continuous numbers
if(timestart<1800 && timestart>800 || endcall<1800 && endcall>800) // Here we have continuous numbers
{
cost = duration*.04; // not duration=duration*.04 since the value turns into cost
cost *= cost_factor; // or cost = duration*.04 * cost_factor
...
tax = cost * .04; /* .04(4%)is the tax */
}
else // now it is "within the time of 1800pm(6:00pm) before 0800am(8:00am)"
{
cost = duration*.40 * cost_factor;
...
}
I suspect that the second expression endcall<=1799 && endcall>=801 needs a further if
well, it doesn't matter if it's c++ or other input.
The point is that the if clause woks as expected (it works even if timestart/endcall are floats or similar). So if your output is not what you expect something else must be wrong. You can use printf() to see what the values are and when it starts to go wrong.