Turbo C help


I'm having assigning range of numbers

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!!!!
Last edited on
Please use the code format tag on the right to format your code. You can edit the original post.

You need to post more of your code. I don't know how those variables are declared or initialised.
please nevermind the variables, its just extra to declare some things, my main problem is the if else statement
The declaration and initialisation of your data is quite important. I can't make assumptions about what you've done.
this time>=1800 && time<=800 and this end>=1800 && end<=800 can never be true
then what code should i put sir?
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

i tried that sir but

if(timestart<=1799 && timestart>=801 || endcall<=1799 && endcall>=801) is not working =(

i tried start time 810 , end call 910 but the operations below doesn't apply
Last edited on
I tried this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <iostream>

using namespace std;

int main()
{
  int timestart = 810;
  int endcall = 910;
  if(timestart<=1799 && timestart>=801 || endcall<=1799 && endcall>=801)
  {
    cout << timestart << " " << endcall << endl;
  }
  return 0;
}
and I got the expected results 810 910
sir the timestart and endcall should be an input code not a declared code

and i think that is c++, i nid the turbo c only pls
Last edited on
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.
Topic archived. No new replies allowed.