# time struct

• 05-24-2007
bazzano
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

Code:

```#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; }```
• 05-24-2007
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.
• 05-24-2007
maven
Hi,

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.
• 05-25-2007
zacs7
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
Code:

```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.