Turbo C help project!


So here's my problem

Code:
tax=gross*.04; /* tax cost 4% */
if (duration>=60 || time>=1800 && time<=800 || end>=1800 && end<=800)
{
gross=duration*.40; /* Duration getting amount by P0.40 per minute */
discount=gross*.15; /* Duration getting discount for 15% if 60minutes have passed */
netcost=gross*.50 /* Duration getting 50% off if the caller calls at the time between 6:00pm (1800) upto 8:00am (0800)
netcost=gross-discount; /* Duration minus discount */
netcost=gross+tax; /* Duration plus tax */
printf("Net Cost: %.2f",netcost);
}
else if (duration>=60 || time<=1799 && time>=801 || end<=1799 && end>=801)
{
gross=duration*.40 /* /* Duration getting amount by P0.40 per minute */
discount=gross*.15; /* Duration getting discount for 15% if 60minutes have passed */
netcost=gross-discount; /* Duration minus discount */
netcost=gross+tax; /* Duration plus tax */
printf("Net Cost: %.2f",netcost);

Problem:
Output for if (duration>=60 || time>=1800 && time<=800 || end>=1800 && end<=800)

Net Cost : 12.74

Output for else if (duration>=60 || time<=1799 && time>=801 || end<=1799 && end>=801)

Net Cost : 12.74

I can't seem to find out why the else if statement "%.2f" function takes the if statement. Any help pls? would be very thankful!

Last edited on
<bump!>
[code] "Your code goes here" [/code]
time>=1800 && time<=800
1
2
3
4
if( duration>=60 or /*...*/ ){
  //...
}
else if(duration>=60 or /*...*/)
make no sense


1
2
3
4
gross=duration*.40;
//...
netcost=gross+tax; /* Duration plus tax */
printf("Net Cost: %.2f",netcost); 
That's what you are doing in both branches. As you are doing the same, the result will be the same.
Your problem is that you are reassigning to the "netcost" variable over and over again instead of updating it. Given I don't know exactly what this is supposed to do, I'm going to assume that you need to change in the if statement:

1
2
3
netcost=gross*.50 /* Duration getting 50% off if the caller calls at the time between 6:00pm (1800) upto 8:00am (0800)*/
netcost=gross-discount; /* Duration minus discount */
netcost=gross+tax; /* Duration plus tax */


to

1
2
3
netcost=gross*.50 /* Duration getting 50% off if the caller calls at the time between 6:00pm (1800) upto 8:00am (0800)*/
netcost=netcost-discount; /* Duration minus discount */
netcost=netcost+tax; /* Duration plus tax */


and in the else if statement:

1
2
netcost=gross-discount; /* Duration minus discount */
netcost=gross+tax; /* Duration plus tax */


to

1
2
netcost=gross-discount; /* Duration minus discount */
netcost=netcost+tax; /* Duration plus tax */
Last edited on
" "Your code goes here"
time>=1800 && time<=800
1
2
3
4
if( duration>=60 or /*...*/ ){
//...
}
else if(duration>=60 or /*...*/)
make no sense


1
2
3
4
gross=duration*.40;
//...
netcost=gross+tax; /* Duration plus tax */
printf("Net Cost: %.2f",netcost);
That's what you are doing in both branches. As you are doing the same, the result will be the same. "

Sir what Im trying to do is, if (duration>=60 || time>=1800 && time<=800 || end>=1800 && end<=800)*(6:00pm (1800pm) upto 800am (8:00am) *the caller will have 50% discount

and else if (duration>=60 || time<=1799 && time>=801 || end<=1799 && end>=801) (military time *(8:00am (800am) upto 6pm(1800pm)* the caller won't have 50% discount.

im really confused how will i do it sir
anybody? pls need badly!
Topic archived. No new replies allowed.