In: Electrical Engineering
Design and implement an interactive program named trip.c that collects information about the user's car and planned travel, and reports back useful information.
The dialog below shows exactly what data should be collected as input and reported as output.
Some Hints to get started /* Not tested not complete code Just to get you started
*/ #include
/* FUNCTION PROTOTYPES */
void WelcomeMessage();
void AskUserForInput(); /* ask and check whether user wants to continue if wants to continue gather information and calculate the results (optional create more functions) */
void PrintTripSummary(float fuel, float minCost, float maxCost, float travelMiles); /* could call this from AskUserForInput(); In a loop and feed it the user input */
/* MAIN */
int main() {
/* Call the functions */
return 0;
}
You do not need to verify user input data. Presume that the user enters reasonable/correct data.
Although you might want to test the results of entering "interesting data" such as alpha data instead of numeric.
Below is the program output. Black is used to illustrate the output, while regular text shows user Input.
Welcome to the Trip Planner!
So you are ready to take a trip? Let me help you plan for your fuel costs and required stops to fill up your tank. ============================================================
Please provide answers to the prompts below and I will display a summary for you when I have computed the results. ============================================================
Please input your car's average miles per gallon (enter 0 to quit) >> 16
Please tell me the range of fuel costs you expect to pay (per gallon).
The lowest per gallon cost of fuel is >> 4.17
The highest per gallon cost of fuel is >> 5.20
Please tell me how many miles you plan to travel >> 900
=============== Trip Summary ==================
You will need to purchase approximately 56 gallons of fuel.
The approximate cost of fuel for your trip is between $235 and $293
=============== End Trip Summary ==================
Please input your car's average miles per gallon (enter 0 to quit) >> 11
Please tell me the range of fuel costs you expect to pay (per gallon).
The lowest per gallon cost of fuel is >> 4.17
The highest per gallon cost of fuel is >> 5.20
Please tell me how many miles you plan to travel >> 1300
=============== Trip Summary ==================
You will need to purchase approximately 118 gallons of fuel.
The approximate cost of fuel for your trip is between $493 and $615
=============== End Trip Summary ==================
Please input your car's average miles per gallon (enter 0 to quit) >> 0
Thank you, please drive safely and have a nice trip!
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
void welcomeMessage();
void AskUserForInput();
void printtripsum(float,float,float,float);
void welcomeMessage()
{
printf("Welcome to the Trip Planner!\nSo you are ready to take a trip?\nLet me help your plan for your fuel costs and required stops to fill up your tank.\n");
printf("Please provide answers to the prompts below and I will display a summary for you when I have computed the results\n");
}
void AskUserForInput()
{
float fuel,minCost,maxCost,travelMiles;
int ch;
while(1)
{
printf("Enter 0 to quit\nelse enter anything\n");
scanf("%d",&ch);
switch(ch)
{
case 0:
exit(1);
default:
printf("Please input your car's average miles per gallon\n");
scanf("%f",&fuel);
printf("Please tell me the range of fuel costs you expect to pay (per gallon).\n");
printf("The lowest per gallon cost of fuel is \n");
scanf("%f",&minCost);
printf("The highest per gallon cost of fuel is\n");
scanf("%f",&maxCost);
printf("Please tell me how many miles you plan to travel\n");
scanf("%f",&travelMiles);
printtripsum(fuel,minCost,maxCost,travelMiles);
}
}
}
void printtripsum(float fuel,float minCost,float maxCost,float travelMiles)
{
printf("Trip Summary\n");
int c=round(travelMiles/fuel);
printf("You will need to purchase approximately%dgallons of fuel\n",c);
int d=round(minCost*(travelMiles/fuel));
int e=round(maxCost*(travelMiles/fuel));
printf("The approximate cost of fuel for your trip is between $%dand$%d\n",d,e);
printf("End trip summary.\n");
}
int main()
{
welcomeMessage();
AskUserForInput();
return 0;
}