Question: My code is not working for the second loop. can anyone help? #include #include #define SPEEDLIMIT 70 #define TOLLRATE .05 #define ENERGYCOST 15.00 void Greeting()

 My code is not working for the second loop. can anyonehelp? #include #include #define SPEEDLIMIT 70 #define TOLLRATE .05 #define ENERGYCOST 15.00void Greeting() { printf("Welcome to the road trip planner "); } void

My code is not working for the second loop. can anyone help?

#include #include #define SPEEDLIMIT 70 #define TOLLRATE .05 #define ENERGYCOST 15.00 void Greeting() { printf("Welcome to the road trip planner "); } void GetYesOrNo(char ch) { if(ch=='Y'||ch=='y') return; printf(" Have a great Trip! "); printf("Press any key to continue . . . "); exit(0); } double distance,price,mileage; void CalculateGasCost(double miles,double *gasCostPtr) { (*gasCostPtr)=miles*price/mileage; printf("The total cost of gas for your trip is $%.2lf ",(*gasCostPtr)); } void CalculateTime(double miles,double *tripTimePtr,int *hoursPtr,int *minutesPtr) { *tripTimePtr=miles/SPEEDLIMIT; *hoursPtr=(int)(*tripTimePtr); *minutesPtr=(*tripTimePtr-*hoursPtr)*60; printf("It will take you %.2lf hours to get to your destination at a rate of 70 MPH ",(*tripTimePtr)); printf("That transalates to %d hours and %d minutes ",(*hoursPtr),(*minutesPtr)); } void CalculateEnergyCost(double tripTime,double *foodCostPtr) { *foodCostPtr=(double)((int)tripTime/4)*(ENERGYCOST); printf("If you stop every 4 hours and spend $15.00 for coffee and snacks, that will cost "); printf("you $%.2lf ",(*foodCostPtr)); } double CalculateCost(double miles,double gasCost,double foodCost,double *tollCostPtr) { (*tollCostPtr)=(double)miles*TOLLRATE; printf("The cost of tolls for your trip at a rate of 5 cents per mile is %.2lf ",(*tollCostPtr)); return(gasCost+foodCost+*tollCostPtr); } int main() { Greeting(); printf("The calculations are based on the driver travelling 70 MPH"); printf(" Stopping every 4 hours for a $15.00 snack "); printf("and a 5 cent per mile toll rate "); char ch; while(1) { printf("Do you want to enter trip details (Y or N) ?"); fflush(stdin); scanf("%c",&ch); GetYesOrNo(ch); printf(" Enter distance of the Trip in miles : "); scanf("%lf",&distance); printf(" Enter the price of gas per gallon : "); scanf("%lf",&price); printf(" How many miles can your car travel on a gallon of gas(MPG) : "); scanf("%lf",&mileage); printf(" "); double gasCostPtr; CalculateGasCost(distance,&gasCostPtr); double tripTimePtr; int hours,minutes; CalculateTime(distance,&tripTimePtr,&hours,&minutes); double foodCostPtr; CalculateEnergyCost(tripTimePtr,&foodCostPtr); double tollCostPtr; double totalCost=CalculateCost(distance,gasCostPtr,foodCostPtr,&tollCostPtr); printf("On this trip you will spend $%.2lf in total for gas,tolls and food ",totalCost); }

You will write a program that will Calculate some of the costs for a road trip . Assume the user will drive an average of 70 MPH . The toll rate is 5 cents a mile . The user will stop and spend $15.00 every 4 hours for food and/or coffee The user will enter the number of miles, the cost of gas per gallon, and the miles per gallon(mpg) of the car. You must have at least 7 user defined functions as follows: //Road trip //preprocessor directives #defineCRTSECURENOWARNINGS #include ---- #define SPEEDLIMIT 70 #define TOLLRATE .05 #define ENERGYCOST 15.00 //Greet the user void Greeting); //Calculations for one road trip void OneRoadTrip); //get input (y or n) to continue void GetYesorNo (char *inputPtr); //Calculate the cost of the gas void CalculateGasCost (double miles, double *gasCostPtr); //calculate the time in hours and minute:s void CalculateTime (double miles, double *tripTimePtr, int *hoursPtr, int *minutesPtr); //calculate the cost of food/energy void CalculateEnergyCost(double tripTime, double *foodCostPtr); //calculate cost of tolls and return the total cost of gas, tolls, and food double CalculateCost (double miles, double gasCost, double foodCost, double tollCostPtr); Additional Requirements Use function prototypes Write comments for each function that will appear in the file before each prototype and again before each function definition Be sure to comment your code adequately Be sure to indent properly. Check your textbook examples to see how it should be done Use meaningful variable names . . . NO Late Submission

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!