hello i have problem on this program i don't know the formula to get the exact parking time, rounded total and total charge...please help me...

Write a C program program to calculate the parking fare for
customers who park their cars in a parking lot when the following information is
given:
a) A character showing the type of vehicle: C for car, B for bus, T for truck
B) An integer between 0 and 24 showing the hour the vehicle entered the lot
c) An integer between 0 and 60 showing the minute the vehicle entered the lot
d) An integer between 0 and 24 showing the hour the vehicle left the lot
e) An integer between 0 and 60 showing the minute the vehicle left the lot

This is a public lot. To encourage people to park for a short period of time, the
management uses two different rates for each type of vehicle, as shown in the
following table:

Vehicle First Rate Second Rate
CAR RM 0.00/hour first 3 hour RM 1.50/hour after 3 hour
TRUCK RM 1.00/hour first 2 hour RM 2.30/hour after 2 hour
BUS RM 2.00/hour for first hour RM 3.70/hour after first hour

No vehicle is allowed to stay in the parking lot later than midnight; it will be tawed away.

The input data consist of a character and a set of four integers representing the
type of vehicle and the entering and leaving hours and minutes. But these
pieces of data must be input into the computer in a user-friendly way. In other
words, the computer must prompt the user to enter each piece of data as show
below. (Note: Red colour indicates typical data)

Type of vehicle? C
Hour vehicle entered lot (0-24)? 14
Minute vehicle entered lot (0-60)? 23
Hour vehicle left lot (0-24)? 18
Minute vehicle left lot (0-60)? 8

The output format is shown below:
This program must first calculate the actual time spent in the parking lot for
each vehicle. You may use the following algorithm:

a) Compare the minute portion of the leaving and the entering time. If the first
one is smaller than the second,
- Add 60 to the minute portion of the leaving time
- Subtract 1 from the hour portion of the leaving time
B) Subtract the hour portions
c) Subtract the minute portions
d) Since there are no fractional hour charges, the program must also round the
parking time up to the next hour before calculating the charge. The program
should use switch statement to distinguish between the different types of
vehicles

PARKING LOT CHARGE
Type of vehicle: C
TIME-IN XX : XX
TIME-OUT XX : XX
-------
PARKING TIME XX : XX
ROUNDED TOTAL XX
-------
TOTAL CHARGE RM XX.XX

please help me hoping for your positive responds...

Sorry, you need to show some work on this. Just posting your assignment and waiting around for some shmuck to do your homework for you, doesn't meet the requirements of the board.

I find it impossible to believe that you can't figure out how to calculate the charges and time, etc.

dont ask for help if you want to learn..learn to hard code thats best the thing to learn programming dont often ask for help.. you can show your codes here for everybody to suggest but dont ask for help to make you the code..learn to pull your hair..

Sorry, you need to show some work on this. Just posting your assignment and waiting around for some shmuck to do your homework for you, doesn't meet the requirements of the board.

I find it impossible to believe that you can't figure out how to calculate the charges and time, etc.

hello sir here is my code...my problem that im not sure if i get the right answer and also how do i get rounding total...please correct me if i am wrong,,please help me sir.... hoping for your positive responds..

#include<stdio.h>
 #include<conio.h>
 #include<ctype.h>
 #include<stdlib.h>


  float minute,lhour,lminute,nhour;
  float hour,x;
  void car();
  void truck();
  void bus();
  void display();
  char num;



 int main()
 {


do
{


    clrscr();


    gotoxy(20,10);
    printf("Menu of VEHICLE");
    gotoxy(20,12);
    printf("B = FOR BUS");
    gotoxy(20,13);
    printf("C = FOR CAR");
    gotoxy(20,14);
    printf("T = FOR TRUCK");
    gotoxy(20,15);
    printf("Q = TO QUIT THE PROGRAM");

    gotoxy(20,20);
    printf("Enter your vehicle type: ");

    scanf("%c",&num);
    num =tolower(num);

  }

 while(num!='c' && num!='t' && num!='b' && num !='q');

    clrscr();

    switch(num)
     {

       case 'c':




		printf("It'a car\n");
		display();
	 
		car();

		break;

       case 't':

		printf("It's a truck\n");
		display();
		truck();
		break;

       case 'b':

		printf("It's a bus\n");
		display();
		bus();
		break;

       case 'q':
	       exit(0);
	       break;
       


     }


     getch();
     return 0;
}


    void display()
     {
		gotoxy(20,12);
		printf("Hour vehicle entered lot: ","\n");
		scanf("%f",&hour);
		gotoxy(20,13);
		printf("Minute vehicle entered lot: ","\n");
		scanf("%f",&minute);
		gotoxy(20,14);
		printf("Hour vehicle left lot: ","\n");
		scanf("%f",&lhour);
		gotoxy(20,15);
		printf("Minute vehicle left lot: ","\n");
		scanf("%f",&lminute);


    }



     void car()
     {
	clrscr();
	gotoxy(20,11);
	printf("Parking lot charge");
	gotoxy(20,13);
	printf("Type of Vehicle: %c" ,num);
	gotoxy(20,14);
	printf("Time in  :%3.f:%.f", hour,minute);
	gotoxy(20,15);
	printf("Time out :%3.f:%.f",lhour,lminute);


	float pt1,pt2,pt3;

	if (lhour > hour)
	{
	 pt1 = lhour-hour;
	}
	else
	{
	pt1 = hour- lhour;
	}

	 if(lminute > minute)
	  {
	   pt2 = lminute - minute;
	  }
	   else
	   {
	   pt2 = minute - lminute;
	   }


	 gotoxy(20,16);
	printf("Parking Time :%2.f:%.f",pt1,pt2);


	float tcharge;
	float exhour,exminute,a,b;
		if (pt1 > 3)

		{
		  exhour = pt1 - 3;
		  tcharge = exhour * 1.50;
		  a = 1.50 / 60;
		  b = pt2 * a;
		  tcharge = tcharge + b;
		}
		else
		{
		 tcharge = 0.00;
		}

	gotoxy(20,17);
	printf("Total Charge :%2.2f",tcharge);

     }

The assignment says to round hours only upward. Which means if you have ANY minutes at all, even 1, you need to increment their hours variable one time.

I like the way the program handles the Midnight problem - very nice.

I'd suggest you make your code more concise, however:

switch(num)
     {

       case 'c':




		printf("It'a car\n");
		display();
	 
		car();

		break;

       case 't':
...

should be:

switch(num)
{
   case 'c':
	printf("It'a car\n");
	display();
	car();
	break;

   case 't':
...

It makes it easier to understand your program, when we can fit more of it, onto one page. Overall, you have a good style, but again, I fail to believe you can't check your answers, by paper and pencil (maybe a calculator).

If you are going to program, you have to get used to testing your program for accuracy - that's the #1 priority.

The assignment says to round hours only upward. Which means if you have ANY minutes at all, even 1, you need to increment their hours variable one time.

I like the way the program handles the Midnight problem - very nice.

I'd suggest you make your code more concise, however:

switch(num)
     {

       case 'c':




		printf("It'a car\n");
		display();
	 
		car();

		break;

       case 't':
...

should be:

switch(num)
{
   case 'c':
	printf("It'a car\n");
	display();
	car();
	break;

   case 't':
...

It makes it easier to understand your program, when we can fit more of it, onto one page. Overall, you have a good style, but again, I fail to believe you can't check your answers, by paper and pencil (maybe a calculator).

If you are going to program, you have to get used to testing your program for accuracy - that's the #1 priority.

hello sir,

thank you for the reply...i apologize for not properly indented my code..about the rounding sir or incrementing that's is my big problem i don't know what to do can you help me on this sir because i don't have idea.thank you in advance hoping for your positive responds...

I answered your rounding question already, but I'll repeat it:

If you have a ticket with a time of 1 hour and 1 minute, the assignment requires you "round" the hour figure up to the next number. So the above figure changes to 2 hours and 0 minutes.

You'll always have 0 minutes after you round up to the next higher hour.

The ONLY time you won't round up an hour, is if the time on the ticket, has a minute number of exactly zero.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.