I'm writing a program that requires 3 functions and I don't quite understanding yet. I tried everything with this program but can't get it work.
*********************************************************************
Write a program that will call a function from main that will return the number of gallons of gas an individual buys, using a “copy of the value”. After this value is returned to main, call another function that will pass two arguments, the number of gallons of gas purchased and the number of liters. The number of gallons of gas you use as a argument must be passed as a copy of the value since no modifications of this value should occur in the function. The number of liters, in this function, will be calculated and returned by reference parameter. The number of liters is equivalent to the number of gallons used, multiplied by 1.7. After this value is returned to main, you are to call a third function that output both values – the number of gallons of gas purchased and its equivalent number of liters. Both of these are to be passed to the function by “copies of the value.”
You are to validate your input of the number of gallons purchased. Gallons cannot be a negative value. You are to request another value and stay in the loop until a valid response is given; do not end the program at this point.
The program must continue to run for three iterations.
***************************************************************************
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
|
#include <iostream>
using namespace std;
double gallon_bought(double);
double gallon_liter(double,double&);
double output_gallons_liters();
int main()
{
double gallons;
cout<<"Please enter total gallons bought: "<<endl;
cin>>gallons;
while (gallons <-1)
{
gallon_bought (gallons);
}
return 0;
}
double gallon_bought(double gallons)
{
return gallons;
}
double gallon_liter(double gallons,double& liters)
{
return liters=gallons*1.7;
}
double output_gallons_liters()
{
cout<<"Total Gallons Bought: "<<gallon_bought<<endl;
cout<<"Total Liters: "<<gallon_liter<<endl;
}
|