Im a beginner at C, and I need some help.
The problem that I have is a problem that calculates parking fee based on several variables.
For instance if it is a car then the first 3 hrs is free, if after 3 hrs 1.50. There's also two more vehicles such as a truck & bus that have unique rates.
Also if the vehicle is parked beyond midnight the vehicle is towed. Time is based on military time ex. 1:00 p.m. is 13:00.
The way that the book wants the info entered is with 5 scanf statements:
Type of vechicle?
Hour vehicle entered lot (0 - 24)?
Minute vehicle entered lot (0 - 59)?
Hour vehicle left lot (0 - 24)?
Minute vehicle left lot (0 - 59)?
So basically I have 4 integers named hrEnter, minEnter, hrOut, minOut. To evaluate the time as a whole I convert them to a float, using a modulo, and add them to the hr variable ex.(12hr + .20min = 12.20). Because I did it this way I get this weird error saying : error C2296: '%' : illegal, left operand has type 'float'. Plus, I get a bunch of these warning C4244: '=' : conversion from 'double' to 'float', possible loss of data.
Besides that, I just found another problem it mentions something about rounding the min. of to the next hour before creating the charge, I've never learned how to do that? This situation seems to get worse everytime I look at it.
I pretty much kind of have the logic worked out, but I'm not sure on a couple of things, such as rounding numbers.
Here's some of the code that I started:
Code:
/* This is Problem 58, Chapter 5 in the C book
Writen By: zero2
*/
#include <stdio.h>
int main (void)
{
/* Local Definitions */
char vehicle;
float bill;
int hrEnter;
int minEnter;
int hrOut;
int minOut;
float minFin;
int hrFin;
float time;
/* Statements */
printf("Type of vechicle?\n");
scanf("%c", &vehicle);
printf("Hour vehicle entered lot (0 - 24)?\n");
scanf("%d", &hrEnter);
printf("Minute vehicle entered lot (0 - 59)?\n");
scanf("%d", &minEnter);
printf("Hour vehicle left lot (0 - 24)?\n");
scanf("%d", &hrOut);
printf("Minute vehicle left lot (0 - 59)?\n");
scanf("%d", &minOut);
if (minEnter > minOut)
{
minFin = minOut + 60;
minFin = (minFin - minEnter) %100 ;
hrFin = hrOut - 1;
hrFin = hrFin - hrEnter;
printf("%d : %2.2f\n", hrFin, minFin);
}
else
{
hrFin = hrOut - hrEnter;
minFin = (minOut - minEnter) %100;
printf("%d : %f\n", hrFin, minFin);
}
if (hrFin < 0)
{
printf("Vehicle later than midnight-Tow\n");
}
if (vehicle = 'c')
if (hrFin <= 3)
{
bill = 0.00;
printf("bill for car: %2.2f\n", bill);
}
else
{
time = hrFin + minFin;
printf("time is %.2f", time);
bill = (time - 3.00) * 1.50;
printf("bill for car: %.2f\n", bill);
}
if (vehicle = 't')
{
if (hrFin <= 2)
time = hrFin + minFin;
bill = time * 1.00;
printf("bill for truck: %.2f\n", bill);
}
else
{
time = hrFin + minFin;
bill = ((time - 2.00) * 2.30) + 2.00;
printf("bill for truck: %.2f\n", bill);
}
return 0;
}
/* main */
/* Results: */
TIA, I appreciate any help or suggestions.