I am trying to write a program that will calculate charges by calling a function to the main branch but I keep Coming back with 0 no mater what I input. Here is my program;
int main()
{
double a = 0, b = 0;
string c;
double r = 0;
// at this point a==0, b==0, c==""
r = billingAmount( a, b, c );
// now you have already set r to what you will see in output
// all this input has no effect on r:
cout << "Enter Hourly Rate :";
cin >> a;
cout << endl;
cout << "Enter Consulting Time In Minutes :";
cin >> b;
cout << endl;
cout << "Is Client Low Income(Enter Y or N) :";
cin >> c;
cout << endl;
cout << r;
return 0;
}
Move the function call from line 8 to line 23. To after the input. You need to first get proper values, before calling a function.
This is different, from say a spreadsheet, where one can enter in cell A3 an equation =A1+A2 and later type values into cells A1 and A2, with immediate re-evaluation of the value of the dependent cell A3.
Line 63: You're declaring a new variable named x. This hides the variable x declared at line 42.
This second x (and the value it was set to) goes out of scope at line 64. The value of this calculation will never be returned.