Thread: Basic C Programming help!

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Feb 2014
    Posts
    10
    Quote Originally Posted by Adak View Post
    You are doing the time calculation yourself - so you don't need time.h. time.h is used mostly when your program needs to work with the reported times from the computer.

    You can keep all your variables about time, as integers, since you have the time broken down into years, days, hours, and minutes. If the time used is 2 hours and 28 minutes, for instance, you don't need to work with 2.47 hours.

    To make your math right, start with the largest quantity, and calculate it first: years. Then get the elapsed months, followed by days, and finally hours and minutes. What you want to do is decide what the rate you're program is charging, will be set up for - do you want to charge by the minute, or by the hour, or ??


    Next, make any calculations that apply for different time periods - looks like 5 hours is one such period.
    Once that's done, have your math change each of these elapsed time units which are greater than zero, into the basic time units you want to charge, and you're good to calculate the rest of the charge.
    Thanks for the response Adak! Thanks for explaining what time.h is, I thought I needed it to calculate the rental duration! When I found out I didn't need it, I broke the rental time down into years/days/hours/mins in order to calculate duration. However, I'm still struggling with that.. how do I convert the month/day/hour/mins ? How do I calculate the duration of rental using them?


    I want to have it so that it charges just $5 for 5 hours or less, $12 for 6 hours or more(up to 24 hours), and each additional hour after 24 hours, charge $0.50. So I guess by the hour.


    Overall, my program is suppose to show the duration of rental in number of hours and minutes including the date, and the final cost of the rental!



    SAMPLE RUN OUTPUT



    Please enter the day and time the bike was rented out
    Year (YYYY): 2014
    Month (1 to 12): 2
    Day (1 to 31): 14
    Hour (0 to 23): 12
    Minutes (0 to 59): 10


    Please enter the day and time the bike was returned
    Year (YYYY): 2014
    Month (1 to 12): 2
    Day (1 to 31): 15
    Hour (0 to 23): 10
    Minutes (0 to 59): 35
    Duration of Rental: 22 hours, 25 min
    The total price comes to: $12.00
    Last edited by convex; 02-14-2014 at 10:52 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Very basic OOP programming in C
    By patishi in forum C Programming
    Replies: 2
    Last Post: 12-20-2013, 03:08 PM
  2. help with my basic c programming
    By chris199236 in forum C Programming
    Replies: 15
    Last Post: 09-25-2012, 09:23 PM
  3. Basic C programming 3
    By vivekgupta in forum C Programming
    Replies: 10
    Last Post: 06-13-2012, 11:22 AM
  4. Basic C programming -1
    By vivekgupta in forum C Programming
    Replies: 29
    Last Post: 06-11-2012, 03:26 PM
  5. basic C-programming Q
    By slyonedoofy in forum C Programming
    Replies: 2
    Last Post: 10-30-2002, 09:54 PM