Question
my code is not working can some help me out. im making a trip planner,in programmin c the code is below: //Program for roadtrip cost
my code is not working can some help me out. im making a trip planner,in programmin c
the code is below:
//Program for roadtrip cost calculation
#include
#define SPEEDLIMIT 70 #define TOLLRATE 0.05 #define ENERGYCOST 15.00
double miles,gasprice,capacity,gasCost,tripTime,hours,minutes,tollCost,totalCost,foodCost;
void Greeting(); //To greet the user
void OneRoadTrip(); //Calculations for one roadtrip
void GetYesOrNo(char *inputptr); //get input y or n to continue
void CalculateGasCost(double miles, double *gasCostPtr); //calculate the cost of the gas
void CalculateTime(double miles, double *tripTimePtr, int *hoursPtr, int *minutesPtr); //calculate the time in hours and minutes
void CalculateEnergyCost(double tripTime, double *foodCostPtr); //calculate the cost of food/energy
double CalculateCost(double miles, double gasCost, double foodCost, double *tollCostPtr); //calculate cost of tolls and return total cost of gas, tolls and food /* This function greets the user for thr road trip planner */ void Greeting() { printf("welcome to the roadtrip planner "); printf("The calculations are based on the driver travelling 70 MPH "); printf("Stopping every four hours for a $15.00 snack and a 5 cent for mile toll"); }
/* This function gets inputs from the user either yesr or no */ void GetYesOrNo(char *inputptr) { printf("Do u want to enter trip details yes or no: "); scanf("%c",&inputptr); }
/* This function gets the input of miles, price of gas per gallon and car capacity. And it prints the output of total cost of trip. */ void OneRoadTrip() { printf("Enter distance of the trip in miles: "); scanf("%lf",&miles); printf("Enter the price of the gas per gallon: "); scanf("%lf",&gasprice); printf("How many miles can your car travel on a gallon of gas(MPG): "); scanf("lf",&capacity); printf("Total cost of gas for trip is: %lf ",gasCost); printf("It will take you %lf hours to reach your destination at a rate of 70 MPH",tripTime); printf(" That translates to %d hours and %d minutes",hours,minutes); printf(" The cost of tolls for your trip at rate of five cents for miles is %lf",tollCost); totalCost= CalculateCost(miles, gasCost,foodCost,&tollCost); printf(" On this trip you will spend a total of %lf for gas,food and tolls.",totalCost); }
/* This function calculates the cost of gas for the whole trip*/
void CalculateGasCost(double miles, double *gasCostPtr) { *gasCostPtr=(miles/capacity)*gasprice; }
/* This function calculates the time taken to reach the destination */
void CalculateTime(double miles, double *tripTimePtr, int *hoursPtr, int *minutesPtr) { int temp; *tripTimePtr = miles/SPEEDLIMIT; *hoursPtr = miles/SPEEDLIMIT; temp = *tripTimePtr - *hoursPtr; *minutesPtr = temp*60; }
/* This function calculates the food costs */ void CalculateEnergyCost(double tripTime, double *foodCostPtr) { *foodCostPtr= (tripTime/4) * ENERGYCOST; }
/* This function calculates the total cost of the journey. It also calls the previous functions to calculate food cost, gas cost and toll cost and return the total cost */ double CalculateCost(double miles, double gasCost, double foodCost, double *tollCostPtr) { *tollCostPtr = miles*TOLLRATE; CalculateGasCost(miles, &gasCost); CalculateTime(miles, &tripTime, &hours, &minutes); CalculateEnergyCost(tripTime,&foodCost); return (*tollCostPtr+foodCost+gasCost); }
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 MPHH . The toll rate is 5 cents a mile .The user will stop and spend S15.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 #defineCRTSECURE NO WARNINGS #includeStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started