Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- #include <stdio.h>
- #define FIRST_CAR_LENGTH 10
- #define NORMAL_CAR_LENGTH 8
- #define CAR_CAPACITY 4
- int main() {
- int num_of_trains, cars;
- int track_length, train_length;
- int lowest_cars, total_train_length;
- int persons;
- int tl, max_tl, max_persons;
- float ratio, sum1, sum2, avg, array_persons[100], array_train[100];
- int i, train_cars;
- int x, g, h;
- printf("What is the total length of the track, in feet?\n");
- scanf("%d", &track_length);
- printf("What is the maximum length of the train, in feet?\n");
- scanf("%d", &train_length);
- i = 0;
- max_persons = 0;
- lowest_cars = 0;
- cars = 0;
- max_tl = (track_length * .25);
- // For loop for max train length
- for(tl=10; tl <= train_length; tl+=8) {
- cars++;
- // 250 / 42 = 5
- num_of_trains = max_tl/train_length;
- // 5*4*5=100
- persons = num_of_trains*CAR_CAPACITY*cars;
- // 5*42 = 210
- total_train_length = num_of_trains*train_length;
- // 80/210
- ratio = (persons*1.00)/total_train_length;
- array_persons[i]=persons;
- array_train[i]=total_train_length;
- i++;
- }
- // Finding the max number of people
- for(g=0; g<i; g++) {
- if(array_persons[g] > max_persons) {
- max_persons = array_persons[g];
- }
- }
- // Finding the lowest number of cars for the train
- for(h=0; h<i; h++) {
- if(array_train[h] > lowest_cars) {
- lowest_cars = array_train[h];
- }
- }
- // Finding the avg for persons
- sum1 = 0;
- for(x=0; x<i; x++)
- sum1+=array_persons[x];
- //Finding the avg for cars
- sum2 = 0;
- for(x=0; x<i; x++)
- sum2+=array_train[x];
- avg = (sum1/i)/(sum2/i);
- printf("Your ride can have at most %d people at one time.\n", max_persons);
- printf("This can be achieved with trains of %d cars,\n", lowest_cars);
- printf("AVG Ratio: %1.2f", avg);
- system("pause");
- return 0;
- }
Add Comment
Please, Sign In to add comment