Jump to content

Recommended Posts

Posted (edited)

Hello guys I need your help! Here's the problem

 

problem: the new telephone company has the following rate structure for long-distance calls:

a. The regular rate for a call is $0.40 per minute

b. any call started after 6:00 PM(1800 hours) but before 8:00 AM(0800 hours) is discounted 50%.

c. any call longer than 60 minutes receives a 15% discount.

d. all call are subject to a 4% federal tax on the cost after any discount.

 

write a program(using turbo c) that take the start time for a call based on aa 24-hour clock and the length if the call in minutes.the gross cost(before any discounts or tax) should be displayed

followed by the net cost(after discount are deducted and tax is added).Use a function to display instructions to the program user, a function to compute the gross cost, and a separate function to compute each discount amount.

 

My code (sorry I'm new to programming in C);

#include<stdio.h>

 

main()

{

int time,end,ave;

clrscr();

 

printf("Starting Time: ");

scanf("%d", &time);

printf("End Call Time: ");

scanf("%d", &end);

 

duration=end-time;

 

printf("Duration of Call: %.0f minutes",duration);

 

getch();

 

}

 

The output should be :

 

Starting time : 0123

End Time : 0224

Duration of Call : 61 minutes

 

but my output is :

 

Starting time : 0123

End Time : 0224

Duration of Call : 101 minutes

 

the problem is my time management code which I have no idea how to convert 12hrs time to 24hrs (military time in turbo c)

Any help? thx in advance.

Edited by Beginner@C
Posted

I don't think that your problem is 12hrs time vs. 24hrs time. The problem is that time 01:23 is not 123 minutes into the day, but rather 60*1 + 23 minutes. C assumes that the digit codes 0123 and 0224 stand for the decimal numbers 123 and 224, and correctly (within this assumption) returns 224-123 = 101. I recommend converting the given time into "minutes since midnight".

 

Unrelated hint: I strongly recommend giving your variables sensible names, e.g. "duration" rather than "ave".

Posted (edited)

sorry for my variables, but If you saw the output which duration is 61 minutes. That is what's required for us to find out how they did it. If I convert 01:23 since midnight to minutes it would be 803 minutes and that is not what is instructed for us to do.

 

My professor told me its something about the operator which I used is "duration=end-time;"

 

any idea?

Edited by Beginner@C
Posted (edited)

No need to apologize for the variable names, it was merely a suggestion of mine. Yes, I do know what your professor means. But I don't want to give too much help for your homework assignment. Try out this code:

#include<stdio.h>
int main() {
 int i, tens, remainder;

 for (i=0; i<20; i+=1) {
   tens = i / 10;           // division by 10, throw away the remainder
   remainder = i % 10;      // the "%" is the modulo operation giving the remainder of above division.
   printf("%i = %i * 10 + %i \n", i, tens, remainder);
 }

 getch();
}

The connection to your time conversion problem hopefully becomes clear once you understand what this code snippet does.

Btw.: I only use c++ myself, so above code is untested. If it does not compile, I hope that necessary corrections are obvious.

Edited by timo
Posted

Ok I really didn't get that code and what you meant by it. Could you give me some hint on converting hours + minutes into minutes? Please! Would be greatful if you can. Thx for your replies.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.