Functions - Logic Error

Here is the code:
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
#include <iostream>

using namespace std;

//declare functions

int main() 
{


double init1, fuel1, rate1, tax1, year1, five1, total1;

//get information from user
getInfo(init1, fuel1, rate1);

//calculate annual tax
year1 = aTax(init1, rate1);

//calculate five year fuel
five1 = fuelfive(fuel1);

//calculate house totals
total1 = house(five1, init1, year1);

//display information
displayInfo(init1, fuel1, year1, total1);


return 0;
}
//**************************getInfo********************************
double getInfo(double& init, double& fuel, double& rate) {
cout << "Please enter the initial house cost: " << endl;
cin >> init;
cout << "Please enter the annual fuel cost: " << endl;
cin >> fuel;
cout << "Please enter the annual tax rate (do not include percent sign):" << endl;
cin >> rate;
}
//**************************aTax**********************************
double aTax(double& init, double& tax) {
double tax;
tax = TR/100;
double year;
year = initial * tax;
return year;
}

//**************************FUELFIVE******************************
double fuelfive(double& fuel) {
double fiveyr;
fiveyr = fuelone * 5;
return fiveyr;
}

//**************************HOUSE********************************
double house(double& five, double& taxyear, double init) {
double fivetax;
fivetax = yearly * 5;
double housetot;
housetot = fivetax + initial + fiveyr;
return housetot;
}

//**************************displayInfo*****************************
void displayInfo(double initial, double fuelone,  double yearly, double total) {
cout << "Initial house cost: " << initial<< endl;
cout << "Annual Fuel Cost: " <<  fuelone << endl;
cout << "Yearly Tax Amount is: " << yearly << endl;
cout << "Total House Cost: " << total << endl;
cout << "---------------------------------------" << endl;
}


If you enter in the initial house cost, the annual fuel cost, and the yearly tax rate, the total house cost is no where near what it is computing it to be. Using the numbers above, and the formula for total house cost, the total for the house should be somewhere around 198,000.
Last edited on
You are screwing up your parameters to 'house':

 
double house(double& fiveyr, double& yearly, double& initial) {


house takes:
1) five year fuel cost
2) yearly tax amount
3) initial cost of house.

 
total1 = house(five1, init1, year1);


You are passing it:
1) five year fuel cost (correct)
2) initial house cost (incorrect, should be yearly tax amount)
3) yearly tax amount (incorrect, should be initial cost)
Last edited on
@Disch - thank you so much. I tried writing this out on paper like three times and just couldn't catch it. Phew!
Topic archived. No new replies allowed.