It took me 2 weeks for my program to work properly, but I decided to change it, but I need help, the idea looks good in my head, but when it’s time to code, I don’t know where to start :( I want the user the program entered its license plate number, and at the end of the day the administrator should be able to see all the license plate numbers of each client and their total number, similar to this
Customer 1 A1546 $ 20
And I would like it to work in the opposite way, the administrator should be able to enter the license plate number, and the information should be displayed. I was thinking about how to do this, and the only way that I think can work is to save all the information in a file, then the program reads the file and displays it? Any help would be truly appreciated. Code below:
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#include <string.h>
char chContinue = 'Y';
int Continue = 1;
int Total=1;
int calculateDiscount(Total) {
char type;
int Total1;
int Discount;
printf("\nDo you have a pilot licence?(Y/N)\n");
scanf("%c", &type);
while( getchar() != '\n' ) ;
if(type == 'Y' || type == 'y') {
Discount = Total * 0.1;
Total1= Total - Discount;
printf("\nYou are eligible for a discount\nYour new price is %d ^_^",Total1);
}
if(type == 'N' || type == 'n') {
printf("Thank you for parking here,please submit this ticket when leaving the compound");
}
return 0;
}
void Lo_op (count,Total) {
char arrayname[6];
int Total2;
printf("\nDo you wish to continue? (Y/N) ");
scanf("%c", &chContinue);
while( getchar() != '\n' ) ;
if (chContinue == 'Y'|| chContinue == 'y' ) {
Continue = 1;
}
else if (chContinue == 'N'|| chContinue == 'n' ) {
printf("enter pass\n");
scanf("%s", arrayname);
strcmp(arrayname,"admin");
printf ("\n>>>Welcome Administrator!<<<\nWhat would you like to do?");
Continue = 2;
}
else {
printf("Invalid input!\n");
}
}
void Print_time () {
printf("\n(Choose a letter corresponding with your choice)\nHow long will you be parking at our facility?\n ");
printf("\n =========MENU===============\n| ");
printf(" A) 30 mins | \n| ");
printf(" B) 1 hour | \n| ");
printf(" C) 2 hours | \n| ");
printf(" D) 5 hours | \n| ");
printf(" E) 1 Day | \n| ");
printf(" F) Greater than 1 Day | \n| ");
printf("==========================\n\n");
}
void Print_carlist () {
printf("\nChoose your type of vehicle\n===========================\n| ");
printf(" 1)Car |\n| ");
printf(" 2)SUV |\n| ");
printf(" 3)Bus |\n| ");
printf(" 4)Truck |\n===========================\n\n");
}
int main() {
char choice;
int Total=1, vehicle, count=1;
int Rate_A = 2, Rate_B = 4, Rate_C = 6, Rate_D = 8, Rate_E = 10, Rate_F = 12;
int Car_rate = 1, Suv_rate = 2, Bus_rate = 3, Truck_rate = 4;
time_t rawtime;
struct tm * timeinfo;
time ( &rawtime );
timeinfo = localtime ( &rawtime );
printf ( "The current date/time is: %s", asctime (timeinfo) );
printf("HELLO AND WELCOME TO THE AUTOMATED PARKING TICKETING SYSTEM\n\nPLEASE FOLLOW THE INSTRUCTIONS ON THE SCREEN\n");
srand(time(NULL));
while (Continue == 1) {
printf("\n You are parker number %d\n ",count);
Print_time ();
scanf("%c",&choice);
while( getchar() != '\n' ) ;
switch (choice) {
case 'A':
Print_carlist();
scanf("%d",&vehicle);
while( getchar() != '\n' ) ;
if((vehicle != 1) && (vehicle != 2) && (vehicle != 3) && (vehicle != 4)) {
printf("Please follow instructions \n");
}
if(vehicle == 1) {
printf("You are parking your Car for 30 mins.\n");
Total = Rate_A * Car_rate;
printf("------------------------------\nYour receipt number is A#%d\n", rand());
printf("You're total is %d,\nPlease submit this ticket when leaving the compound\n-------------------------------",Total);
count=count+1;
Total=Total+1;
}
if(vehicle == 2) {
printf("You are parking your SUV for 30 mins.\n");
Total = Rate_A * Suv_rate;
printf("------------------------------\nYour receipt number is A#%d\n", rand());
printf("You're total is %d,\nPlease submit this ticket when leaving the compound\n-------------------------------",Total);
count=count+1;
Total=Total+1;
}
if(vehicle == 3) {
printf("You are parking your Bus for 30 mins.\n");
Total = Rate_A * Bus_rate;
printf("------------------------------\nYour receipt number is A#%d\n", rand());
printf("You're total is %d,\nPlease submit this ticket when leaving the compound\n-------------------------------",Total);
count=count+1;
Total=Total+1;
}
if(vehicle == 4) {
printf("You are parking your Truck for 30 mins.\n");
Total= Rate_A * Truck_rate;
printf("------------------------------\nYour receipt number is A#%d\n", rand());
printf("You're total is %d,\nPlease submit this ticket when leaving the compound\n-------------------------------",Total);
count=count+1;
Total=Total+1;
}
Lo_op (count,Total);
break;
case 'B':
Print_carlist();
scanf("%d", &vehicle);
while( getchar() != '\n' ) ;
if((vehicle != 1) && (vehicle != 2) && (vehicle != 3) && (vehicle != 4)) {
printf("Please follow instructions \n");
}
if(vehicle == 1) {
printf("You are parking your Car for 1 hour.\n");
Total = Rate_B * Car_rate;
printf("------------------------------\nYour receipt number is B#%d\n", rand());
printf("You're total is %d,\nPlease submit this ticket when leaving the compound\n-------------------------------",Total);
count=count+1;
Total=Total+1;
}
if(vehicle == 2) {
printf("You are parking your SUV for 1 hour.\n");
Total = Rate_B * Suv_rate;
printf("------------------------------\nYour receipt number is B#%d\n", rand());
printf("You're total is %d,\nPlease submit this ticket when leaving the compound\n-------------------------------",Total);
count=count+1;
Total=Total+1;
}
if(vehicle == 3) {
printf("You are parking your Bus for 1 hour.\n");
Total = Rate_B * Bus_rate;
printf("------------------------------\nYour receipt number is B#%d\n", rand());
printf("You're total is %d,\nPlease submit this ticket when leaving the compound\n-------------------------------",Total);
count=count+1;
Total=Total+1;
}
if(vehicle == 4) {
printf("You are parking your Truck for 1 hour.\n");
Total=Rate_B*Truck_rate;
printf("------------------------------\nYour receipt number is B#%d\n", rand());
printf("You're total is %d",Total);
count=count+1;
Total=Total+1;
}
Lo_op ();
break;
case 'C':
Print_carlist();
scanf("%d",&vehicle);
while( getchar() != '\n' ) ;
if((vehicle != 1) && (vehicle != 2) && (vehicle != 3) && (vehicle != 4)) {
printf("Please follow instructions \n");
}
if(vehicle == 1) {
printf("You are parking your Car for 2 hours.\n");
Total = Rate_C * Car_rate;
printf("------------------------------\nYour receipt number is C#%d\n", rand());
printf("\nYou're total is %d", Total);
count=count+1;
Total=Total+1;
}
if(vehicle == 2) {
printf("You are parking your SUV for 2hours .\n");
Total = Rate_C * Suv_rate;
printf("------------------------------\nYour receipt number is C#%d\n", rand());
printf("You're total is %d,\nPlease submit this ticket when leaving the compound\n-------------------------------",Total);
count=count+1;
Total=Total+1;
}
if(vehicle == 3) {
printf("You are parking your Bus for 2 hours .\n");
Total = Rate_C * Bus_rate;
printf("------------------------------\nYour receipt number is C#%d\n", rand());
printf("You're total is %d,\nPlease submit this ticket when leaving the compound\n-------------------------------",Total);
count=count+1;
Total=Total+1;
}
if(vehicle == 4) {
printf("You are parking your Truck for 2hours .\n");
Total = Rate_C * Truck_rate;
printf("------------------------------\nYour receipt number is C#%d\n", rand());
printf("You're total is %d,\nPlease submit this ticket when leaving the compound\n-------------------------------",Total);
count=count+1;
Total=Total+1;
}
Lo_op ();
break;
case 'D':
Print_carlist();
scanf("%d", &vehicle);
while( getchar() != '\n' ) ;
if((vehicle != 1) && (vehicle != 2) && (vehicle != 3) && (vehicle != 4)) {
printf("Please follow instructions \n");
}
if(vehicle == 1) {
printf("You are parking your Car for 5 hours.\n");
Total = Rate_D * Car_rate;
printf("------------------------------\nYour receipt number is D#%d\n", rand());
printf("You're total is %d,\nPlease submit this ticket when leaving the compound\n-------------------------------",Total);
count=count+1;
Total=Total+1;
}
if(vehicle == 2) {
printf("You are parking your SUV for 5 hours .\n");
Total = Rate_D * Suv_rate;
printf("------------------------------\nYour receipt number is D#%d\n", rand());
printf("You're total is %d,\nPlease submit this ticket when leaving the compound\n-------------------------------",Total);
count=count+1;
Total=Total+1;
}
if(vehicle == 3) {
printf("You are parking your Bus for 5 hours .\n");
Total = Rate_D * Bus_rate;
printf("------------------------------\nYour receipt number is D#%d\n", rand());
printf("You're total is %d,\nPlease submit this ticket when leaving the compound\n-------------------------------",Total);
count=count+1;
Total=Total+1;
}
if(vehicle == 4) {
printf("You are parking your Truck for 5 hours .\n");
Total = Rate_D * Truck_rate;
printf("------------------------------\nYour receipt number is D#%d\n", rand());
printf("You're total is %d,\nPlease submit this ticket when leaving the compound\n-------------------------------",Total);
count=count+1;
Total=Total+1;
}
Lo_op ();
break;
case 'E':
Print_carlist();
scanf("%d",&vehicle);
while( getchar() != '\n' ) ;
if((vehicle != 1) && (vehicle != 2) && (vehicle != 3) && (vehicle != 4)) {
printf("Please follow instructions \n");
}
if(vehicle == 1) {
printf("You are parking your Car for 1 day .\n");
Total = Rate_E * Car_rate;
printf("------------------------------\nYour receipt number is E#%d\n", rand());
printf("You're total is %d,\nPlease submit this ticket when leaving the compound\n-------------------------------",Total);
calculateDiscount(Total);
count=count+1;
Total=Total+1;
}
if(vehicle == 2) {
printf("You are parking your SUV for 1 day .\n");
Total = Rate_E * Suv_rate;
printf("------------------------------\nYour receipt number is E#%d\n", rand());
printf("You're total is %d,\nPlease submit this ticket when leaving the compound\n-------------------------------",Total);
calculateDiscount(Total);
count=count+1;
Total=Total+1;
}
if(vehicle == 3) {
printf("You are parking your Bus for 1 day .\n");
Total = Rate_E * Bus_rate;
printf("------------------------------\nYour receipt number is E#%d\n", rand());
printf("You're total is %d,\nPlease submit this ticket when leaving the compound\n-------------------------------",Total);
calculateDiscount(Total);
count=count+1;
Total=Total+1;
}
if(vehicle == 4) {
printf("You are parking your Truck for 1 day .\n");
Total = Rate_E * Truck_rate;
printf("------------------------------\nYour receipt number is E#%d\n", rand());
printf("You're total is %d,\nPlease submit this ticket when leaving the compound\n-------------------------------",Total);
calculateDiscount(Total);
count=count+1;
Total=Total+1;
}
Lo_op ();
break;
case 'F':
Print_carlist();
scanf("%d", &vehicle);
while( getchar() != '\n' ) ;
if((vehicle != 1) && (vehicle != 2) && (vehicle != 3) && (vehicle != 4)) {
printf("Please follow instructions \n");
}
if(vehicle == 1) {
printf("You are parking your Car for more than one day.\n");
Total = Rate_F * Car_rate;
printf("------------------------------\nYour receipt number is F#%d\n", rand());
printf("You're total is %d,\nPlease submit this ticket when leaving the compound\n-------------------------------",Total);
calculateDiscount(Total);
count=count+1;
Total=Total+1;
}
if(vehicle == 2) {
printf("You are parking your SUV for more than one day.\n");
Total = Rate_F * Suv_rate;
printf("------------------------------\nYour receipt number is F#%d\n", rand());
printf("You're total is %d,\nPlease submit this ticket when leaving the compound\n-------------------------------",Total);
calculateDiscount(Total);
count=count+1;
Total=Total+1;
}
if(vehicle == 3) {
printf("You are parking your Bus for more than one day.\n");
Total = Rate_F * Bus_rate;
printf("------------------------------\nYour receipt number is F#%d\n", rand());
printf("You're total is %d,\nPlease submit this ticket when leaving the compound\n-------------------------------",Total);
calculateDiscount(Total);
count=count+1;
Total=Total+1;
}
if(vehicle == 4) {
printf("You are parking your Truck for more than one day.\n");
Total = Rate_F * Truck_rate;
printf("------------------------------\nYour receipt number is F#%d\n", rand());
printf("You're total is %d",Total);
calculateDiscount(Total);
count=count+1;
Total=Total+1;
}
Lo_op ();
break;
default:
printf("\nSorry your choice is not valid, please enter the letter associated with your choice!\n");
break;
}
}
return 0;
}