Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a program in C language where the output should consist of three lines. The first line outputs the maximum number of passengers on the

Write a program in C language where the output should consist of three lines. The first line outputs the maximum number of passengers on the roller coaster at any one time with a single statement of the following format:
Your ride can have at most X people on it at one time.
The second line should output the number of cars in the train that achieves this maximum with a single statement of the following format:
This can be achieved with trains of Y cars.
Note: If there are multiple ways in which the maximum number of people can be
supported, output the smallest number of cars that achieves this maximum. (Thus, if both 2 cars and 4 cars lead to 100 people on the ride and this is the maximum, then your program should output 2 cars.)
The third line should simply output the average value of people to length, as:
AVG Ratio: XXXX.XXX
Here is my code so far:
#include
#define FIRST_CAR_LENGTH 10
#define NORMAL_CAR_LENGTH 8
#define CAR_CAPACITY 4
int main(void){
int TRKlength, TRNlength, SafeTRK, passengers;
int SmallTrnAvail, TotSmallTrn, ActualTlength;
int CarsPerTRN, excessTRN, numTRN, totCars;
int i;
printf("What is the total length of the track in feet?
");
scanf("%d", &TRKlength);
SafeTRK = TRKlength*.25;
printf("What is the maximum length of a train in feet?
");
scanf("%d", &TRNlength);
SmallTrnAvail = TRNlength - FIRST_CAR_LENGTH;
TotSmallTrn = SmallTrnAvail / NORMAL_CAR_LENGTH;
ActualTlength = FIRST_CAR_LENGTH + NORMAL_CAR_LENGTH * TotSmallTrn;
CarsPerTRN =1+ TotSmallTrn;
numTRN = SafeTRK/ActualTlength;
totCars = numTRN * CarsPerTRN;
passengers = CAR_CAPACITY * totCars;
printf("Your ride can have at most %d people on it at one time
", passengers);
return 0;
}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions