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 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
|
#include <iostream>
using namespace std;
double price (double a, double b, double c, double d, double&, double& );
int main ()
{
double start_gas, end_gas, gas_value;
double start_electric, end_electric, electric_value;
cout<<"Enter the starting value for gas:"<<endl;
cin>>start_gas;
cout<<endl;
cout<<"Enter the ending value for gas:"<<endl;
cin>>end_gas;
cout<<endl;
cout<<"Enter the starting value for electric:"<<endl;
cin>>start_electric;
cout<<endl;
cout<<"Enter the ending value for electric:"<<endl;
cin>>end_electric;
cout<<endl<<endl;
price (start_gas, end_gas, start_electric, end_electric, gas_value, electric_value);
cout<<gas_value<<endl;
cout<<electric_value<<endl;
system ("pause");
return 0;
}
double price (double start_gas, double end_gas, double start_electric, double end_electric, double& gas_value, double& electric_value)
{
double gas, gas_value1, gas_value2;
double electric, electric_value1, electric_value2;
gas = (end_gas)-(start_gas);
electric = (end_electric)-(start_electric);
if (gas <= 31)
{
gas_value = gas*.504;
return gas_value;
}
else
{
gas_value1 = 31*.504;
gas_value2 = (gas-31)*.824;
gas_value = gas_value1+gas_value2;
return gas_value;
}
//this is where the problem is
if (electric <= 238.7)
{
electric_value = electric*.094;
return electric_value;
}
else
{
electric_value1 = 238.7*.094;
electric_value2 = (electric-238.7)*.133;
electric_value = electric_value1+electric_value2;
return electric_value;
}
}
|