Thread: time struct

  1. #1
    Musicman - Canora
    Join Date
    Aug 2005

    time struct

    Hey guys im trying to return the expiry time for a hypathetical car park meter using this program. The parking costs 1.10 per hour im trying to write this function to test this question.

    so if i insert 2.00 that should give me a little less then 2 hours how would i calculate that?
    Then return the expiry time using a time struct

    Im using scanf because its just a test program

    #include <stdlib.h>
    #include <stdio.h>
    #include <time.h>
    int parking(time_t *time, float insert);
    int main(void)
      time_t time;
      int pt;
      float input;
      pt = parking(&time, input);
      return EXIT_SUCCESS;	
    int parking(time_t *time, float insert)
      float parkingCost = 1.10;
      float expire = 0.00;
      scanf("%f", &insert);
      if(insert < parkingCost)
      	 printf("You have inserted money for less then an hour\n");
      	 return 0;
      else if(insert > parkingCost)
      	printf("You have inserted money past the hour\n");
      	expire = insert + parkingCost;
      printf("%f", expire);
      return  expire;

  2. #2
    Registered User
    Join Date
    Sep 2006
    So 110 / 60 would equal the cost in pennies, per minute, for parking. If you need a smaller figure, divide by 60 again, to get the pennies per second charge.

  3. #3
    Registered User
    Join Date
    Dec 2005



    You can use simple concept of quantitative analysis.
    like if some thing in 1 hour cost 1.10 then how much it will cost for two hour.

    Now you hav to just develop programming logic to do this.
    you can convert hour to minute or seconds to make it more efficient.
    S_ccess is waiting for u. Go Ahead, put u there.

  4. #4
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    I would work out how much it costs in cents per minute, since the lowest amount they could insert would most likely be 5c... Not to mention increased accuracy, So:

    * Multiply the cents per minute by the time (gives you how many cents it requires), (cents per minute * time (in minutes))

    For example
    CentsPerMinute = (1.10 * 100) / 60 (1.10 per hour)
    Time = 120 (2 hours)
    Cost = CentsPerMinute * time
    echo "It costs " Cost " cents or " Cost / 100 " dollars"
    And to work out the change, subtract the Cost from the cents entered. Or to work out how much time you get for X cents, transpose the formula to make Time the subject.
    Last edited by zacs7; 05-25-2007 at 12:30 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Assignment HELP!!
    By cprogrammer22 in forum C Programming
    Replies: 35
    Last Post: 01-24-2009, 02:24 PM
  2. Replies: 1
    Last Post: 12-03-2008, 03:10 AM
  3. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  4. Request for comments
    By Prelude in forum A Brief History of
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM
  5. I apologize. Good bye.
    By doubleanti in forum A Brief History of
    Replies: 14
    Last Post: 05-03-2002, 06:51 PM