### Problem with return value

My program is to display the values for someones gas and electric bill. It has an if-else for a bill to account for a baseline and over-baseline price for both the gas and electric. The function that computes the gas bill is correct but when the electric bill is computed and displayed it prints the same weird scientific notation value regardless of what the start and end electric values are. So what is wrong? Can you show or tell me b/c everything else if right except that.
 ``1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677`` ``````#include 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:"<>start_gas; cout<>end_gas; cout<>start_electric; cout<>end_electric; cout<
electric_value is never calculated and therefore you're printing an uninitialized value.

You return at either line 46 or line 54. You never reach line 56.

So how do I go about fixing that?
Are you saying the second if-else is never executed or executed properly?
Function `price()` passes gas_value and electric_value by reference. That means the function does not need to use a `return` statement for these values.

Unless you wanted some sort of combined total, there doesn't seem to be a need for a return statement at all, the function could have a return type of void and get rid of all the return statements, since these are preventing any code after the return was reached from being executed.
 So how do I go about fixing that? Are you saying the second if-else is never executed or executed properly?

The second if-else is never executed. A function can only return once, and when it returns, it exits. When you return the gas value, it exits, before the second if-else begins.

As Chervil says, your passing the results of the calculations back as function arguments anyway, so there's no need to return any values. And you're not using the return value from price() in main anyway.
Last edited on
Topic archived. No new replies allowed.