Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I DO NOT UNDERSTAN FUNCTION CALLS YET. THIS IS MY CODE FOR CALCULATING GAS PRICE

ID: 3905950 • Letter: I

Question

I DO NOT UNDERSTAN FUNCTION CALLS YET. THIS IS MY CODE FOR CALCULATING GAS PRICES. CAN SOMEONE PLEASE BREAK IT DOWN INTO THESE FUNCTION CALLS..

void banner();

This function prints a friendly message to the user,

informing her that your specific application is running.

void getInputs();

This function will obtain all the values of all input variables you need from the user. Note that the signature shown above does not show the output parameters, you will need. The number of parameters depends on the parameters you will obtain from the user.

calculateOutputs();

This function will take in all “inputs” as input parameters and provide outputs to the calling function. If you have only one output, it is ok to use “return -- Option 2”, in which case the return type will not be void. If you have more than two outputs, you will need to use Option 1 (use more parameters that are pointers), in which case the return type will be void. In either case the return value(s) must be finally stored in variable(s), and array(s) of test() function.

void printOne();

This function will display the results of a single execution of the code.

Therefore it must take all inputs and all outputs as “input parameters”. b

void printAll(double/int* array, int size);

This function will display the contents of the array that contains results of all executions in a friendly manner.

void test();

Throughout the development process, you must built test code inside the test function. This is critical to seek help. Help for code that is not properly tested will be delayed.

**********************************************************


/********************************
********************************/
#include <stdio.h>


// 1.)Check the range of each input provided by the user to ensure that the user provides values within acceptable range.
// 2.)Allow the user to run the program several times over and over again.
// 3.)Clearly separate the test code from the rest of the code.
// You will use: loops, condition statements and arrays in this assignment.
// https://www.fueleconomy.gov/feg/best-worst.shtml
//https://www.fueleconomy.gov/feg/Find.do?action=sbs&id=36941
#define CAPACITY 10
int main()
{
double milepergal;//Gallon capacity of vehicle.
double price; //Price per gallon of gas.
double totalcost; //Total cost of gallons of gasoline purchased.
double miles;
char road;
char exit;
double totalcosts[CAPACITY];
int totalcostsSize=0;
int i;
for (i=0;1<CAPACITY;i++)
{
printf("Welcome to the Cost of Gasoline per Trip Calculator ");
printf("================================================= ");
//obtaining inputs
do{
printf("What is the Miles per Gallon of the Vehicle you're driving? ");
scanf("%lf", &milepergal);
}while(milepergal <= 10 || milepergal >= 130);
do{
printf("What is the current cost of Gasoline per Gallon? ");
scanf("%lf", &price);
}while(price < 2 || price >5);
do{
printf("How many miles do you intend on traveling? ");
scanf("%lf", &miles);
}while (miles < 1 || miles > 600);
printf ("Please choose (A/B) for driving in city or highway respectively: ");
scanf(" %c",&road);
//Calculations
if(road=='A'|| road=='a'){
// Calculations for mpg in city
totalcost = (miles/milepergal) * price;
} else{
// Calculations for mpg on highway
totalcost = (miles/milepergal*.75) * price;
}
totalcosts[i]=totalcost;
totalcostsSize++;
// Test code
printf("Road=%c ",road);
printf("Your trip is estimated to cost approximately $%lf", totalcost);
printf(" ");
printf("Please enter 'E' or 'C' to continue:" );
scanf(" %c", &exit);
if(exit=='E') break;
}
for(i=0;i<totalcostsSize;i++){
printf("TOTALCOST[%d]=%.2lf ",i,totalcosts[i]);
}
return 0;
}


Explanation / Answer

here is your modified code : ----------->>>>>>>>

#include <stdio.h>
// 1.)Check the range of each input provided by the user to ensure that the user provides values within acceptable range.
// 2.)Allow the user to run the program several times over and over again.
// 3.)Clearly separate the test code from the rest of the code.
// You will use: loops, condition statements and arrays in this assignment.
// https://www.fueleconomy.gov/feg/best-worst.shtml
//https://www.fueleconomy.gov/feg/Find.do?action=sbs&id=36941
#define CAPACITY 10

void banner(){
system("cls");//function to clear the screen
printf("Welcome to the Cost of Gasoline per Trip Calculator ");
printf("================================================= ");
}

void getInputs(double *milepg,double *price,double *miles,char *road){
do{
printf("What is the Miles per Gallon of the Vehicle you're driving? ");
scanf("%lf",milepg);
}while(*milepg <= 10 || *milepg >= 130);
do{
printf("What is the current cost of Gasoline per Gallon? ");
scanf("%lf",price);
}while(*price < 2 || *price >5);
do{
printf("How many miles do you intend on traveling? ");
scanf("%lf",miles);
}while (*miles < 1 || *miles > 600);
printf ("Please choose (A/B) for driving in city or highway respectively: ");
scanf(" %c",road);
}
double calculateOutputs(char road,double miles,double milepergal,double price){
double totalcost = 0.0;
if(road=='A'|| road=='a'){
// Calculations for mpg in city
totalcost = (miles/milepergal) * price;
} else{
// Calculations for mpg on highway
totalcost = (miles/milepergal*.75) * price;
}

return totalcost;
}
void printOne(char road,double totalcost){
printf("Road=%c ",road);
printf("Your trip is estimated to cost approximately $%lf", totalcost);
printf(" ");
}
void printAll(double* array, int size){
int i;
system("cls");
for(i=0;i<size;i++){
  printf("TOTALCOST[%d]=%.2lf ",i,array[i]);
}
}

void test(){
double milepergal;//Gallon capacity of vehicle.
double price; //Price per gallon of gas.
double totalcost; //Total cost of gallons of gasoline purchased.
double miles;
char road;
char exit;
double totalcosts[CAPACITY];
int totalcostsSize=0;
int i;
for (i=0;1<CAPACITY;i++)
{
  //call greetings
  banner();
  //obtaining inputs
  getInputs(&milepergal,&price,&miles,&road);
  //Calculations
  totalcost = calculateOutputs(road,miles,milepergal,price);
  totalcosts[i]=totalcost;
  totalcostsSize++;
  // printing one
  printOne(road,totalcost);
  printf("Please enter 'E' or 'C' to continue:" );
  scanf(" %c", &exit);
  if(exit=='E') break;
}
//printing all
printAll(totalcosts,totalcostsSize);
}
int main()
{
test();
return 0;
}