Hi, I ma having some trouble with arrays, I can't fill them up, the value entered replaces the first one, and the rest of array have value 0, what did I do wrong.
Thanks in advanceCode:#include<stdio.h> int hour_in[200], min_in[200]; int hour_out[200], min_out[200]; int in_AM_PM[200], out_AM_PM[200]; int charge[200]; int hour[200]; int overnight[200]; int total_hours=0; int amount_collected=0; int i; void get_time_in_and_out(void) { int i=0; printf("Enter time in\n");//enter time in printf("\tHour:"); scanf("%i",&hour_in[i]); printf("\n\tMinuts:"); scanf("%i",&min_in[i]); printf("\n0 - AM ; 1 - PM\t"); scanf("%i",&in_AM_PM[i]); if(in_AM_PM[i]==1&&hour_in[i]<12) { hour_in[i]+=12; } else if(in_AM_PM[i]==0&&hour_in[i]==12) { hour_in[i]+=12; } else { hour_in[i]+=0; } printf("\nEnter time out\n");//enter time out printf("\tHour:"); scanf("%i",&hour_out[i]); printf("\n\tMinuts:"); scanf("%i",&min_out[i]); printf("\n0 - AM ; 1 - PM\t"); scanf("%i",&out_AM_PM[i]); if(out_AM_PM[i]==1&&hour_out[i]<12) hour_out[i]+=12; else if(out_AM_PM[i]==0&&hour_out[i]==12) hour_out[i]+=12; else hour_out[i]+=0; } void find_overnight(int x) { for(i=0; i<x; ++i) { if (hour_in[i]>4&&hour_in[i]<16) overnight[i]=1; else overnight[i]=hour[i]*0; } } void calculate_hours(int x) { int total, i; for(i=0; i<=x; ++i) { total=(((hour_out[i]*60)+min_out[i])-((hour_in[i]*60)+min_in[i])); hour[i]=total/60; total_hours+=hour[i]; } //for(i=0;i<car;++i)//printf("%i\n",hour[i]); } void calculate_charge(int x) { int i; for(i=0; i<x; ++i) { if(overnight[i]==0) charge[i]=11; else if((hour[i]*overnight[i])>10&&(hour[i]*overnight[i])<=24) charge[i]=27; else if((hour[i]*overnight[i])>=0&&(hour[i]*overnight[i])<=1) charge[i]=8; else if((hour[i]*overnight[i])<2) charge[i]=12; else if((hour[i]*overnight[i])<3) charge[i]=16; else charge[i]=22; } for(i=0;i<x;++i) { amount_collected+=charge[i]; } } void print_table(int x) { printf("Car\tTime in\t Time out\tHours\tAmount\n"); for(i=0; i<x; ++i) { printf("%2i\t%4i:%i\t %4i:%i\t %i\t%3i\n",i+1,hour_in[i],min_in[i],hour_out[i],min_out[i],hour[i],charge[i]); } printf("Total Hours Parked:\t%i\n",total_hours); printf("Amount Collected:\t%i\n",amount_collected); } void main(void) { int Done=1; int car=0; do { ++car; printf("Car#%i:\n\n", car); get_time_in_and_out(); printf("==============================="); printf("\n1 -Next car\n0 -Done "); scanf("%i",&Done); printf("===============================\n\n"); }while(Done==1); calculate_hours(car); find_overnight(car); calculate_charge(car); print_table(car); }



LinkBack URL
About LinkBacks


