Write your question here.
Here is what I need to do...
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.
********************************************************
But I having problems running the program, it wont run but I have no errors showing up.
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 48 49 50 51 52
|
#include <iostream>
using namespace std;
double gallons(double);
double galllons_liters(double,double&);
double out_gallons_lit(double,double);
int main ()
{
double liters;
double const gall_liters=1.7;
double gall;
while (gall<-1)
{
cout<<"Please enter total gallons bought: "<<endl;
cin>>gall;
if(gall==-1)
{
cout<<"Please Enter a Positve Number"<<endl;
cin>>gall;
}
gallons(gall);
}
cout<<"Your Your total gas bought is: "<<out_gallons_lit(gall, liters)<<endl;
}
double gallon(double gall)
{
return gall;
}
double gallons_liters(double gall,double& liters)
{
return liters=gall*1.7;
}
double out_gallons_lit(double gall, double liters)
{
return gall, liters;
}
|