为什么这段代码不起作用?
基本思路:
每辆车可以坐4个人。每列火车的第一节车厢长 10 英尺,随后的每节车厢长 8 英尺。火车只能占据总轨道长度的25%。
目标是打印出可以填充火车轨道的最大人数,用户输入最大轨道长度和最大火车长度。
//Roller Coaster Capacity
//Justin Castillo, Section 1, COP 3223, 2/9/2013
//This program calculates the maximum number of people that can be on the
//track at one time.
int main(void) {
int max_people_train;
int num_cars_train;
int total_num_trains;
int max_length_track;
int max_length_train;
int max_people_track;
int prev_max_people_track;
int prev_total_num_trains, i;
printf("Please enter the track length:\n");
scanf("%d", &max_length_track);
printf("Please enter the max length of the train:\n");
scanf("%d", &max_length_train);
for (i=10; i<=max_length_train; i+8) {
num_cars_train = ((i-10)/8 +1);
max_people_train = (num_cars_train)*4;
total_num_trains = max_length_track/i;
max_people_track = total_num_trains*max_people_train;
prev_max_people_track = prev_total_num_trains * max_people_train;
prev_total_num_trains = max_length_track/(i-8);
if (prev_max_people_track > max_people_track)
max_people_track = prev_max_people_track;
}
printf("Your ride can have at most %d people on the track,\n", max_people_track);
printf("This can be achieved with trains of %d cars.\n", num_cars_train);
system("pause");
return 0;
}