Why does this code not work?
Basic idea:
Each car can have 4 people in it.
The first car of each train is 10 feet long, and each subsequent car is 8 feet long.
The train can only occupy 25% of the total track length.
The goal is to print out the maximum number of people that can populate the train track, with user input for the maximum track length and the maximum train length.
//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;
}
I’m guessing it has something to do with this:
Try: