What is wrong with this code cause im not getting the correct ratio of total people to cumulative length?
Code:
#include<stdio.h>
#include<stdlib.h>
//define constant variables
#define FIRST_CAR_LENGTH 10
#define NORMAL_CAR_LENGTH 8
#define CAR_CAPACITY 4
int main(void){
//Set up some variable with values that come from input or calculations
double t_track;
double train_length;
double useable_track;
int t_cars, maxcar, n;
int t_people, maxpeep;
int t_trains;
int i;
float ratio_array[100];
float sum;
//initialize array values to zero
for(i=0;i<99;i++){
ratio_array[i]=0;
}
maxpeep = 0;
maxcar = 0;
//Prompting the user for data and assigning it to variables
printf("What is the total length of the track, in feet?\n");
scanf("%lf", &t_track);
printf("what is the maximum length of a train, in feet?\n");
scanf("%lf", &train_length);
useable_track = (t_track * .25);
//for loop to calculate all different train lengths
for(i=10;i<=train_length;i+=8){
t_cars = ((i-FIRST_CAR_LENGTH)/(NORMAL_CAR_LENGTH))+1;
t_trains = (useable_track/i);
t_people = (t_cars * CAR_CAPACITY * t_trains);
if(maxpeep < t_people)
maxpeep = t_people;
if(maxcar < t_cars)
maxcar = t_cars;
ratio_array[t_cars-1] = (t_people/(i*t_cars));
n++;
}
for(i=0;i<99;i++){
sum += ratio_array[i];
}
printf("your ride can have at most %d people on it at one time\n", maxpeep);
printf("This can be achieved with trains of %d cars\n", maxcar-1);
printf("AVG ratio: %.3f\n", (sum/n));
printf("\n");
system("Pause");
return 0;
}