Hi,
Please I need help writing a C program that simulates a parking machine meter.
The instructions are on the following link:
http://cop2270.mlahlou.info/files/HW4S13.pdf
My problem is that when "printing the receipt", under the Garage Location I get a number (from 1 to 3). How can I make it print valet parking, garage parking and economy parking (as the example) for each case?
Thank you in advance
so far I have this:
Code:
#include <stdio.h>
#include <stdlib.h>
int main (void)
{
int opt = 0, h = 0, m = 0;
float pay = 0;
FILE*data;
data = fopen ("parking_receipt.txt","w");
void print()
{
fprintf(data, "\nRECEIPT\n\n \nGarage Location \t\tAmount of Time \t\t\tTotal Due"
"\n%d \t\t%dh %dmin \t\t%.2f", opt, h, m, pay);
}
do{
system("cls");
printf("\nWELLCOME TO THE MIAMI INTERNATIONAL AIRPORT\n\n");
printf("We offer you the following parking options:\n\n");
printf("1. Valet Parking\n");
printf("2. Garage Parking\n");
printf("3. Economy Parking\n");
printf("4. Print Receipt and/or Exit\n");
printf("\nPlease select your parking option:");
scanf("%d", &opt);
switch(opt)
{
case 1:
system("cls");
printf("\nValet Parking\n\n");
printf("\nRates:\n");
printf("\t\t0 - 3 hours: $18.00");
printf("\n\t\t3 - 24 hours: $30.00");
printf("\n\t\tmax $30.00/day");
printf("\n\nPlease enter the amount of hours that you're going to stay:");
scanf("%d%d", &h, &m);
if(h <= 3)
{
pay = 18;
printf("%.2f\n", pay);
print();
}
else
{
if(h > 3, h <= 24)
{
pay = 30;
printf("%.2f\n", pay);
print();
}
}
getch();
break;
case 2:
system("cls");
printf("\nGarage Parking\n\n");
printf("\nRates:\n");
printf("\t\tEvery 20 min: $2.00");
printf("\n\t\tmax $17.00/day");
printf("\n\nmaximun rate applies after 160 min");
printf("\n\nPlease enter the amount of hours and min that you're going to stay:");
scanf("%d%d", &h, &m);
if(h <= 2, m < 60, ((h*60) + m) <= 160)
{
pay = (h*6) + (m*.1);
printf("%.2f\n", pay);
print();
}
else
{
if(h > 2, m < 60, (h*60) + m > 160)
{
pay = 17;
printf("%.2f\n", pay);
print();
}
}
getch();
break;
case 3:
system("cls");
printf("\nEconomy Parking\n\n");
printf("\nRates:\n");
printf("\t\t0 - 3 hours: $3.00/hour");
printf("\n\t\tmax $8.00/day");
printf("\n\nmaximun rate applies after 160 min");
printf("\n\nPlease enter the amount of hours and min that you're going to stay:");
scanf("%d%d", &h, &m);
if(h <= 3, m < 60,((h*60) + m) < 160 )
{
pay = (h*3) + (m*.05);
printf("%.2f\n", pay);
print();
}
else
{
if(h > 3, m > 160,((h*60) + m) > 160 )
{
pay = 8;
printf("%.2f\n", pay);
print();
}
}
getch();
break;
}
}while(opt !=4);
fclose(data);
return 0;
}