Code:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main(void)
{
int num_trains, max_train_length, track_length, train_length;
int avail_track_for_trains, avail_small_cars, small_cars, num_people;
int true_train_cars, true_train_length, amount_of_trains;
int tl, max_track, win_people, n_cars, max_tl;
int best_car, c_car_length;
int n, repeat, i;
char str1[50], str2[50];
printf("Type in which choice you want: 1, 2, 3, or 4");
scanf("%d" , &n);
while(n!=4)
{
if(n==1)
{
int main(void)
{
int num_trains, max_train_length, track_length, train_length;
int avail_track_for_trains, avail_small_cars, small_cars, num_people;
int true_train_cars, true_train_length, max_track_length, amount_of_trains;
//Ask for user input. Max track length and max train length
printf("What is the total length of the track?\n");
scanf("%d" , &track_length);
printf("What is the maximum length you want the trains to be?\n");
scanf("%d" , &max_train_length);
//Calculations
avail_track_for_trains = track_length*.25;
small_cars = (max_train_length-10)/8;
true_train_cars = small_cars+1;
true_train_length = small_cars*8+10;
amount_of_trains = avail_track_for_trains/true_train_length;
num_people = true_train_cars*amount_of_trains*4;
//Display results
printf("You can fit %d people on your trains.\n" , num_people);
getchar();
while(getchar()!='\n');
return 0;
}
}
else if(n==2)
{
int main(void)
{
int tl, num_people, max_track, win_people, n_cars, max_tl, num_trains;
int best_car, c_car_length;
float ratio_array[1000], ratio;
n_cars=0;
win_people=0;
//Prompt user for maximum train length and maximum track length
printf("What is the maximum track length?\n");
scanf("%d" , &max_track);
printf("What is the maximum train length?\n");
scanf("%d" , &max_tl);
//Run through all possible train combinations
for(tl=10; tl<=max_tl; tl+=8)
{
n_cars++;
num_trains=(.25*max_track)/tl;
num_people=n_cars*num_trains*4;
if(num_people>win_people)
{
win_people=num_people;
best_car=n_cars;
}
c_car_length=tl*num_trains;
ratio=(1.0*num_people)/c_car_length;
ratio_array[n_cars-1]=ratio;
}
//Display Results
printf("You can fit %d people on your trains with %d "
"cars per train.\n" , win_people, best_car);
printf("Your ratio is %f.\n" , ratio);
getchar();
while(getchar()!='\n')
return 0;
}
}
else if(n==3)
{
int main(void)
{
int n, repeat, i;
char str1[50], str2[50];
//Prompt user for strings for repeat test
printf("How many times do yoo want your program to run?\n");
scanf("%d" , &n);
printf("What are the %d last names you want to check for repeats?\n" , n);
scanf("%s" , str1);
//Set Flag
repeat=0;
//Compare string 1 with the rest of the strings
for(i=1; i<=n-1; i++)
{
scanf("%s" , str2);
if(strcmp(str1, str2)==0)
repeat=1;
}
//Display Output
if(repeat==1)
printf("Your first word repeats.\n");
else
printf("Your first word doesnt repeat.\n");
while(getchar()!='n');
getchar();
return 0;
}