Hi, im almost finnished a program, however it keeps crashing after the user enters a value after the first choice in the menu. Heres the code:
Code:
#include <stdio.h>
#include <stdlib.h>
struct details //array for storing each structure of car details
{
int rego[50]; //storage for registration
int drego[50]; //storage for the reigstration of the exiting car
int amin[50]; //storage for the arrival in minutes
int ahour[50]; //storage for the arrival in hours
int dmin[50]; //storage for the departure in minutes, which is added later on by user
int dhour[50]; //storage for the departure in hours, which is added later on by user
//int days[50];
int total[50];
/*int pay=0;
int cost;
int j=0;*/
}newcar;
int pay=0;
int cost;
int j=0;
int feecalc()
{
int timediffh; //difference in hours calculation integer
int timediffm; //difference in minutes calculation integer
int min; //resultant calculation of minutes in car park
int hour; //resultant calculation of hours in car park
float fee; //the initial flat fee of $2
float extraa; //float for the subtraction of 3 from the number of hours
float extrab; //float for the multiplication of the $1.5 per hour
float extrac; //float for the rounding of minutes, adding an aditional hour
float total; //grand total of what is charged to that car
float minutecharge; //rounding minutes off to the next hour
timediffh = newcar.dhour[pay] - newcar.ahour[pay];
timediffm = newcar.dmin[pay] - newcar.amin[pay];
if(timediffm < 0) //if the number of arrival time has a higher value than the departure time, then add 60
{
min = timediffm +60;
hour = timediffh - 1;
}
else
{
min = newcar.dmin[pay] - newcar.amin[pay]; //other wise continue on with the original calculation
hour = newcar.dhour[pay] - newcar.ahour[pay];
}
if(hour < 3)
{
fee = 2.00;
newcar.total[pay] = fee;
}
else
{
fee = 2.00;
extraa = hour - 3;
extrab = extraa*1.5;
newcar.total[pay] = fee + extrab;
}
if ((newcar.dmin > 0) && (hour >= 3))
{
extrac = +1.5;
newcar.total[pay] = fee + extrab + extrac;
}
if (total >= 10)
{
newcar.total[pay] = 10;
}
printf("Number of hours in car park:%ihours %iminutes\n",hour,min);
printf("Cost for the number of hours is:$%.2f\n",newcar.total[pay]);
}
int entry()
{
int plate, face;
printf("###Car Arrival###\n");
printf("Please Enter a 4 Number Registration Plate:\n");
scanf("%i", plate);
for(face = 0;face < 51; face ++)
{
if(plate == newcar.rego[j])
{
printf("you suck");
entry();
}
}
newcar.rego[j] = plate;
if(newcar.rego[j] < 10000)
{
printf("WRONG");
}
newcar.rego[j] = 0;
printf("Please Enter The Time of Car Arrival in hours(24 Hour Time Used):\n");
scanf("%i", &newcar.ahour[j]);
if(newcar.ahour[j] > 24)
{
printf("Fail");
entry();
}
printf("Please Enter The Time of Car Arrival in Minutes:\n");
scanf("%i", &newcar.amin[j]);
if (newcar.amin[j] > 60)
{
printf("Fail");
entry();
}
j++;
main();
}
int dept()
{
int nope;
int exitplate;
printf("Please Enter a 4 Number Registration Plate number:\n");
scanf("%i", &exitplate);
for(nope = 0; nope < 51; nope++)
{
if(exitplate == newcar.rego[nope])
{
newcar.drego[pay] = exitplate;
if(exitplate < 10000)
{
printf("your gay");
dept();
}
printf("Please Enter The Time of Car Departure in hours(24 Hour Time Used):\n");
scanf("%i", &newcar.dhour[pay]);
if(newcar.dhour[pay] > 24)
{
printf("EFG");
}
if(newcar.dhour[pay] < newcar.ahour[nope])
{
printf("Error, cannot leave before entering");
dept();
}
printf("Please Enter The Time of Car Departure in Minutes:\n");
scanf("%i", &newcar.dmin[pay]);
if(newcar.dmin[pay] > 60)
{
printf("Fail");
dept();
}
}}}
int main()
{
int user;
printf("1. Car Arrival\n");
printf("2. Car Departure\n");
printf("3. Print Out of Daily Data\n");
printf("4. Quit Program\n");
scanf("%i", &user);
switch(user)
{
{
case 1://Writes to car structure
entry();
case 2:
dept();
feecalc();
case 3:
printf("Bull........\n");
return main();
}
}}