im new at C, actually just started programming in general, and im having a good amount of problems with this program.

#include <stdio.h>

int main(void)

char vehicle;
char car;
char truck;
int hrsn, minn;
int hrso, mino;
int time;
int rt;
int amo;

printf("What time did you park(military time-(hh,mm))?");
scanf("%d,%d", &hrsn, &minn);

printf("What time did you leave(military time-(hh,mm))?");
scanf("%d,%d", &hrso, &mino);

printf("Where you driving a car or truck?");
scanf("%c", &vehicle );

if (hrsn < (hrso - 1) && minn > mino)
{ hrso = hrso - 1;
mino = mino + 60;
if (mino - minn > 1 && mino - minn < 30)
mino - minn = 30;

else if (mino - minn > 30 && mino - minn < 60)
mino - minn = 60;

else {
mino - minn = 00;

rt = hrso - hrsn:mino - minn;

if (vehicle == car)
{ scanf("%c", &car);
if (time < 3)
{car = 0;
{car = 1.5;

else {
scanf("%c", &truck):
if (time < 2)
{truck = 1;
{truck = 2.3;
amo = rt * %c;

Printf("Time in %d:%d\n", hrsn, minn);
Printf("Time out %d:%d\n", hrso, mino);

printf("Parking Time %d\n", time);
printf("Rounded time %d\n", rt);

printf("Ammount Owed $ %d\n", amo);

return 0;


im trying to do this:

Problem 2: (P) Write a C 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, T for truck.
b. An integcr 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 Table
CAR $0 / hr first 3 hr $1.50 / hr after 3 hr
TRUCK $1 / hr first 2 hr $2.30 / hr after 2 hr
Input data consists of a character and a set of four integers. The character represents type of vehicle and the four integers indicate: Hour entered the lot, Minute entered lot, Hour exited lot, and Minute exited the lot.

Output should be like:

Type of vehicle: <car , bus, or truck>

TOTAL CHARGE $ _____.__

im sure there are alot of mistakes
any help is greatly appriciated

Edited by Nick Evan: Add code-tags

7 Years
Discussion Span
Last Post by uskok

you've got a lot of issues. for instance, these lines:

mino - minn = 30;
mino - minn = 60;
mino - minn = 00;

you can't make assignments like that. i'm having a really hard time following your logic, but you need to have the one variable being assigned on the LHS and the expression it gets assigned to on the RHS. like: mino = minn + 30 .

another thing is you have "car" as a type char (single character) then you later try to assign it the value 1.5. that's not going to work at all. you can only assign it char values, like: car = 'c'; or car = 'T'; or car = 0x63; // ascii for 'c' or car = 0x54; // ascii for 'T' there are other problems but i'm going to stop now


You don't need to bother with both hours and minutes in every calculation. Instead of saying something like "time-in is thirteen hours and forty-four minutes", you can express it as (13*60 + 44) minutes and work with that one variable.
That would make it easier to compare starting time with ending time.

In the lines 47 and 58, you are waiting for a key to be pressed, even though you have the information about the type of vehicle already stored in the variable "vehicle".

At lines 48 and 59, you are evaluating the variable "time", even though you haven't used it before and its value is undefined.

What is rt = hrso - hrsn:mino - minn; intended to do? It's meaningless in C, and I cannot figure out in what way you wanted it to calculate rounded time. Isn't rounded time just the number of hours? Or number of hours plus one, if you round it up.

If amo is integer, you cannot store real numbers in it without losing information. Change it to float.

scanf("%d,%d", &hrso, &mino);
printf("Where you driving a car or truck?");
scanf("%c", &vehicle );

This code will not work, because scanf() requires you to press enter key when you are finished with entering data; however, it doesn't read that enter, leaving it in the input stream. What happens is that the next scanf() will read that enter and assign it to vehicle.
To prevent that, you could just write getchar(); before the last scanf().

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.