1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
|
int main(void) {
#define first_car 10
#define normal_car 8
#define car_cap 4
int trackL, maxTL, maxp, i, key, imax, TL[i], ncars[i], ntrains[i], tcars[i], CCL[i], peop[i];
float avgR[i];
printf("What is the total length of the track, in feet?\n");
scanf("%d", &trackL);
printf("What is the maximum length of a train, in feet?\n");
scanf("%d", &maxTL);
maxp=0;
TL[0]=10;
ncars[0]=1;
imax=(maxTL-10)/8;
for(i=0;i<imax;i++) {
ntrains[i]= maxTL/TL[i];
tcars[i]=ntrains[i]*ncars[i];
CCL[i]=ntrains[i]*TL[i];
peop[i]=tcars[i]*car_cap;
avgR[i]=peop[i]/CCL[i];
if(peop[i]>maxp){
maxp= peop[i];
key= i;
}
}
printf("Your ride can have at most %d people on it at one time\n", maxp);
printf("This can achieved with trains of %d cars\n", ncars[key]);
printf("AVG Ratio: %7.3f\n", avgR[key]);
return 0;
}
|