hey guys i'm really having trouble with my c programming assignment which is mostly to do with making the program go back to the start.
ok heres the issues:
when the word admin is entered at the car registration input the program displays a report screen.
Code:
void carreg(void)
{ /* carreg function start */
printf("Please Enter Car Registration\n");
printf(" \n");
scanf("%s",reg); /* data input 1 (car registration) */
printf(" \n");
printf(" \n");
} /* carreg function end */
void input(void)
{ /* input function start */
check=strcmp(reg,"admin"); /* check for attendant password */
if(check==0) /* if attendant password correct */
{
system("cls");
cash=((float)totalcash)/100;
halfvalue=half*20;
onevalue=one*60;
twovalue=two*120;
threevalue=three*150;
allvalue=all*400;
ticketvalue=(((float)halfvalue)+((float)onevalue)+((float)twovalue)+((float)threevalue)+((float)allvalue))/100;
printf("Total Number of Cars Using The Car Park: %d\n",car);
printf("Total Number of Half an Hour Tickets: %d\n",half);
printf("Total Number of One Hour Tickets: %d\n",one);
printf("Total Number of Two Hour Tickets: %d\n",two);
printf("Total Number of Three Hour Tickets: %d\n",three);
printf("Total Number of All Day Tickets: %d\n",all);
printf("Value of Tickets Produced: œ%.2f\n",ticketvalue);
printf("Total Cash Taken: œ%.2f\n",cash);
printf(" \n");
printf("Press any key to reset software...");
getch();
system("cls");
initialise();
}
when a key is pressed the program should then load the initialise function (the first function in the program), but it doesnt. instead it jumps to the output function.
Code:
void output(void)
{ /* output function start */
system("cls");
getdate(&today);
printf("Car Registration: %s\n",reg);
printf("Date: %d/%d/%d\n",today.da_day,today.da_mon,today.da_year);
printf("Amount Paid: œ%.2f\n",paid);
printf("Issued: %02d:%02d\n",now.ti_hour,now.ti_min);
printf("Expires: %02d:%02d\n",expirehour,expiremin);
} /* output function end */
However the function call in the last function (reset) which jumps back to the carreg function works.
Code:
void reset(void)
{ /* reset function start */
printf(" \n");
printf(" \n");
printf("Press Any key To Continue...");
getch();
coin=0;
totalinserted=0;
totalcash=0;
system("cls");
carreg();
} /* reset function end */
another problem then occurs. the program asks for a car registration input and if anything at all is entered the application terminates.
the next issue is i use a rogue value (-1) to terminate the user input during the input function. this value then gets added to the total (i.e. it takes away -1 from the total) when i attemp to correct this by adding 1 back onto the total the program adds 3 to the total. for example if the total is 30 and i dont remove the rogue value it comes out as 29 but if i add 1 to the total the total comes out as 32. the code below continues from the strcmp command in the input function shown in the first piece of code i quoted.
Code:
else /* if attendant password incorrect */
{
while(coin!=-1)
{ /* coin input loop start */
printf(" \n");
printf("Enter -1 To End Input\n");
printf(" \n");
printf("Please Enter Coin\n");
printf(" \n");
scanf("%d",&coin); /* data input 2 (coin) */
while((coin!=10)&&(coin!=20)&&(coin!=50)&&(coin!=100)&&(coin!=-1))
{ /* validation loop 1 start */
printf(" \n");
printf(" \n");
printf("Invalid Coin\n");
printf(" \n");
printf("Enter -1 To End Input\n");
printf(" \n");
printf("Please Enter Coin\n");
printf(" \n");
scanf("%d",&coin); /* data input 2 (coin) */
} /* validation loop 1 end */
totalinserted=totalinserted+coin;
} /* coin input loop end */
/* check amount */
if(totalinserted<20)
{
printf(" \n");
printf(" \n");
printf("Not Enough Money!");
printf(" \n");
printf(" \n");
coin=0;
input();
}
else
if(totalinserted<60)
{
half++;
car++;
}
else
if(totalinserted<120)
{
one++;
car++;
}
else
if(totalinserted<150)
{
two++;
car++;
}
else
if(totalinserted<400)
{
three++;
car++;
}
else
{
all++;
car++;
}
/* calculate expiry time */
if(totalinserted<60)
{
gettime(&now);
expiremin=now.ti_min+30;
expirehour=now.ti_hour;
if(expiremin>59)
{
expiremin=expiremin-60;
expirehour=now.ti_hour+1;
}
}
else
if(totalinserted<120)
{
gettime(&now);
expiremin=now.ti_min;
expirehour=now.ti_hour+1;
}
else
if(totalinserted<150)
{
gettime(&now);
expiremin=now.ti_min;
expirehour=now.ti_hour+2;
}
else
if(totalinserted<400)
{
gettime(&now);
expiremin=now.ti_min;
expirehour=now.ti_hour+3;
}
else
{
expiremin=00;
expirehour=20;
}
/* check expiry time */
if(expirehour>19)
{
expiremin=00;
expirehour=20;
}
totalcash=totalcash+totalinserted;
}
} /* input function end */
void process(void)
{ /* process function start */
paid=((float)totalinserted)/100;
} /* process function end */
the next function is the output function (which i have alreaded quoted) which the total is shown on.
the main function may help
Code:
main()
{ /* program start */
system("cls"); /* clear screen to remove data from previous applications */
/* function calls */
initialise();
carreg();
input();
process();
output();
reset();
} /* program end */
if you require the whole code just ask and i will post it