Need help in displaying the annual costs of my code??

Everything else displays and runs, except my annual cost function...
Need help!!

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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
 #include <iostream>
using namespace std;

//Function Declarations
float getLoanPayment();
float getInsurance();
float getGas();
float getOil();
float getTires();
float getMaintenance();
float calculateTotalMonthlyCosts(float loanPaymentCost, float insuranceCost, float gasCost, float oilCost, float tiresCost, float maintenanceCost);
float calculateTotalAnnualCosts(float totalMonthlyCosts);
void showResult(float loanPaymentCost, float insuranceCost, float gasCost, float oilCost, float tiresCost, float maintenanceCost);
void showCalculateTotalMonthlyCostsResults(float loanPaymentCost,
 float insuranceCost,
	float gasCost,
	float oilCost,
	float tiresCost,
	 float maintenanceCost);


int main() // start of the main function

{
	//Declare and Initialze Variables
	float loanPaymentCost = 0;
	float insuranceCost = 0;
	float gasCost = 0;
	float oilCost = 0;
	float tiresCost = 0;
	float maintenanceCost = 0;
	float totalMonthlyCosts = 0;
	float totalAnnualCosts = 0;
	int annualCost = 12;


	// Loan Payment Cost
	loanPaymentCost = getLoanPayment();

	//Get Insurance Cost
	insuranceCost = getInsurance();

	//Get Gas
	gasCost = getGas();

	// Get Oil Cost 
	oilCost = getOil();

	// Get Tires Cost
	tiresCost = getTires();

	// Get Maintenance Cost
	maintenanceCost = getMaintenance();

	// Display results
	showResult(loanPaymentCost, insuranceCost, gasCost, oilCost, tiresCost, maintenanceCost);

	// Calculate toal Monthly costs 
	totalMonthlyCosts =calculateTotalMonthlyCosts(loanPaymentCost, insuranceCost, gasCost, oilCost, tiresCost, maintenanceCost);
	// Display results

	cout << "Your total monthly cost is: " << totalMonthlyCosts << endl;

	// Calculate total Annual Cost
	totalAnnualCosts = calculateTotalAnnualCosts(annualCost, totalMonthlyCosts);

	//Display results
	cout << " Your total Annual cost is:" << totalAnnualCosts << endl;

	
	char quitKey;
	//Delay
	cout << "Press any key and Enter to end program: ";
	cin >> quitKey;

	//End of Program
	return 0;
}
// Function to get Loan Payment Cost
float getLoanPayment()
{
	float loanPaymentCost;
	cout << "Enter the Loan Payment Cost and press ENTER" << endl;
	cin >> loanPaymentCost;
	//return result
	return loanPaymentCost;
}

// Function to get Insurance Cost
float getInsurance()
{
	float insuranceCost;
	cout << "Enter the Insurance Cost and Press Enter" << endl;
	cin >> insuranceCost;
	//return result
	return insuranceCost;
}

// Function to get Gas Cost
float getGas()
{
	float gasCost;
	cout << "Enter the gas cost and Press Enter" << endl;
	cin >> gasCost;
	// return result
	return gasCost;
}

// Function to get Oil cost
float getOil()
{
	float oilCost;
	cout << "Enter the oil cost and press Enter" << endl;
	cin >> oilCost;
	// return result
	return oilCost;
}

// Function to get Tires Cost
float getTires()
{
	float tiresCost;
	cout << " Enter the tire cost and press Enter" << endl;
	cin >> tiresCost;
	// return result
	return tiresCost;
}
// Function to get Maintenance cost

float getMaintenance()
{
	float maintenanceCost;
	cout << " Enter the maintenance cost and press Enter" << endl;
	cin >> maintenanceCost;
	// return result
	return maintenanceCost;
}


void showResult(float loanPaymentCost, float insuranceCost, float gasCost, float oilCost, float tiresCost, float maintenanceCost)
{
	//Display all the purchase amount, state tax, county tax, total tax, and total of sale
	cout << "Loan Payment Cost= " << loanPaymentCost << endl;
	cout << "Insurance Cost = " << insuranceCost << endl;
	cout << "Gas Cost = " << gasCost << endl;
	cout << "Oil Cost = " << oilCost << endl;
	cout << "Tires Cost = " << tiresCost << endl;
	cout << "Maintenance Cost= " << maintenanceCost << endl;
}

// Function to calculate total Monthly Costs
float calculateTotalMonthlyCosts(float loanPaymentCost,
 float insuranceCost,
 float gasCost,
	float oilCost,
	float tiresCost,
	float maintenanceCost)

{
	float totalMonthlyCosts;
	
	totalMonthlyCosts = (loanPaymentCost + insuranceCost + gasCost + oilCost + tiresCost + maintenanceCost);

		return totalMonthlyCosts;
}

// Function to calculate total Annual Costs

float calculateTotalAnnualCosts(float totalMonthlyCosts)
{
	float totalAnnualCosts;
	totalAnnualCosts = int annualCost * totalMonthlyCosts;
	return totalAnnualCosts;
}



Are you sure you want to use this piece of code?
totalAnnualCosts = int annualCost * totalMonthlyCosts;
so line 169 is expecting one value
float calculateTotalAnnualCosts(float totalMonthlyCosts)

line 75 is trying to send it 2 values
calculateTotalAnnualCosts(annualCost, totalMonthlyCosts)

You forgot to include annualCost in the arguments of your funtion when declaring it both at the start and at the function itself.

You can compare to the fixed version I did:

#include <iostream>
using namespace std;

//Function Declarations
float getLoanPayment();
float getInsurance();
float getGas();
float getOil();
float getTires();
float getMaintenance();
float calculateTotalMonthlyCosts(float loanPaymentCost, float insuranceCost, float gasCost, float oilCost, float tiresCost, float maintenanceCost);
float calculateTotalAnnualCosts(float totalMonthlyCosts);
void showResult(float loanPaymentCost, float insuranceCost, float gasCost, float oilCost, float tiresCost, float maintenanceCost);
void showCalculateTotalMonthlyCostsResults(float loanPaymentCost,
 float insuranceCost,
	float gasCost,
	float oilCost,
	float tiresCost,
	 float maintenanceCost);


int main() // start of the main function

{
	//Declare and Initialze Variables
	float loanPaymentCost = 0;
	float insuranceCost = 0;
	float gasCost = 0;
	float oilCost = 0;
	float tiresCost = 0;
	float maintenanceCost = 0;
	float totalMonthlyCosts = 0;
	float totalAnnualCosts = 0;
	int annualCost = 12;


	// Loan Payment Cost
	loanPaymentCost = getLoanPayment();

	//Get Insurance Cost
	insuranceCost = getInsurance();

	//Get Gas
	gasCost = getGas();

	// Get Oil Cost 
	oilCost = getOil();

	// Get Tires Cost
	tiresCost = getTires();

	// Get Maintenance Cost
	maintenanceCost = getMaintenance();

	// Display results
	showResult(loanPaymentCost, insuranceCost, gasCost, oilCost, tiresCost, maintenanceCost);

	// Calculate toal Monthly costs 
	totalMonthlyCosts =calculateTotalMonthlyCosts(loanPaymentCost, insuranceCost, gasCost, oilCost, tiresCost, maintenanceCost);
	// Display results

	cout << "Your total monthly cost is: " << totalMonthlyCosts << endl;

	// Calculate total Annual Cost
	totalAnnualCosts = calculateTotalAnnualCosts(annualCost, totalMonthlyCosts);

	//Display results
	cout << " Your total Annual cost is:" << totalAnnualCosts << endl;

	
	char quitKey;
	//Delay
	cout << "Press any key and Enter to end program: ";
	cin >> quitKey;

	//End of Program
	return 0;
}
// Function to get Loan Payment Cost
float getLoanPayment()
{
	float loanPaymentCost;
	cout << "Enter the Loan Payment Cost and press ENTER" << endl;
	cin >> loanPaymentCost;
	//return result
	return loanPaymentCost;
}

// Function to get Insurance Cost
float getInsurance()
{
	float insuranceCost;
	cout << "Enter the Insurance Cost and Press Enter" << endl;
	cin >> insuranceCost;
	//return result
	return insuranceCost;
}

// Function to get Gas Cost
float getGas()
{
	float gasCost;
	cout << "Enter the gas cost and Press Enter" << endl;
	cin >> gasCost;
	// return result
	return gasCost;
}

// Function to get Oil cost
float getOil()
{
	float oilCost;
	cout << "Enter the oil cost and press Enter" << endl;
	cin >> oilCost;
	// return result
	return oilCost;
}

// Function to get Tires Cost
float getTires()
{
	float tiresCost;
	cout << " Enter the tire cost and press Enter" << endl;
	cin >> tiresCost;
	// return result
	return tiresCost;
}
// Function to get Maintenance cost

float getMaintenance()
{
	float maintenanceCost;
	cout << " Enter the maintenance cost and press Enter" << endl;
	cin >> maintenanceCost;
	// return result
	return maintenanceCost;
}


void showResult(float loanPaymentCost, float insuranceCost, float gasCost, float oilCost, float tiresCost, float maintenanceCost)
{
	//Display all the purchase amount, state tax, county tax, total tax, and total of sale
	cout << "Loan Payment Cost= " << loanPaymentCost << endl;
	cout << "Insurance Cost = " << insuranceCost << endl;
	cout << "Gas Cost = " << gasCost << endl;
	cout << "Oil Cost = " << oilCost << endl;
	cout << "Tires Cost = " << tiresCost << endl;
	cout << "Maintenance Cost= " << maintenanceCost << endl;
}

// Function to calculate total Monthly Costs
float calculateTotalMonthlyCosts(float loanPaymentCost,
 float insuranceCost,
 float gasCost,
	float oilCost,
	float tiresCost,
	float maintenanceCost)

{
	float totalMonthlyCosts;
	
	totalMonthlyCosts = (loanPaymentCost + insuranceCost + gasCost + oilCost + tiresCost + maintenanceCost);

		return totalMonthlyCosts;
}

// Function to calculate total Annual Costs

float calculateTotalAnnualCosts(float totalMonthlyCosts)
{
	float totalAnnualCosts;
	totalAnnualCosts = int annualCost * totalMonthlyCosts;
	return totalAnnualCosts;
}
Try this
*edit, sorry removed some test code I had put in*

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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176

 #include <iostream>
using namespace std;

//Function Declarations
float getLoanPayment();
float getInsurance();
float getGas();
float getOil();
float getTires();
float getMaintenance();
float calculateTotalMonthlyCosts(float loanPaymentCost, float insuranceCost, float gasCost, float oilCost, float tiresCost, float maintenanceCost);
float calculateTotalAnnualCosts(float totalMonthlyCosts);
void showResult(float loanPaymentCost, float insuranceCost, float gasCost, float oilCost, float tiresCost, float maintenanceCost);
void showCalculateTotalMonthlyCostsResults(float loanPaymentCost,
 float insuranceCost,
	float gasCost,
	float oilCost,
	float tiresCost,
	 float maintenanceCost);

// Function to calculate total Annual Costs
float calculateTotalAnnualCosts(int x, float y )
{
//	float totalAnnualCosts;
//	totalAnnualCosts = x * y;
	return x * y;
}

int main() // start of the main function
{
	//Declare and Initialze Variables
	float loanPaymentCost = 0;
	float insuranceCost = 0;
	float gasCost = 0;
	float oilCost = 0;
	float tiresCost = 0;
	float maintenanceCost = 0;
	float totalMonthlyCosts = 0;
	float totalAnnualCosts = 0;
	int annualCost = 12;


	// Loan Payment Cost
	loanPaymentCost = getLoanPayment();

	//Get Insurance Cost
	insuranceCost = getInsurance();

	//Get Gas
	gasCost = getGas();

	// Get Oil Cost 
	oilCost = getOil();

	// Get Tires Cost
	tiresCost = getTires();

	// Get Maintenance Cost
	maintenanceCost = getMaintenance();

	// Display results
	showResult(loanPaymentCost, insuranceCost, gasCost, oilCost, tiresCost, maintenanceCost);

	// Calculate toal Monthly costs 
	totalMonthlyCosts =calculateTotalMonthlyCosts(loanPaymentCost, insuranceCost, gasCost, oilCost, tiresCost, maintenanceCost);
	// Display results

	cout << "Your total monthly cost is: " << totalMonthlyCosts << endl;

	// Calculate total Annual Cost
	totalAnnualCosts = calculateTotalAnnualCosts(annualCost, totalMonthlyCosts);

	//Display results
	cout << " Your total Annual cost is:" << totalAnnualCosts << endl;

	
	char quitKey;
	//Delay
	cout << "Press any key and Enter to end program: ";
	cin >> quitKey;

	//End of Program
	return 0;
}


// Function to get Loan Payment Cost
float getLoanPayment()
{
	float loanPaymentCost;
	cout << "Enter the Loan Payment Cost and press ENTER" << endl;
	cin >> loanPaymentCost;
	//return result
	return loanPaymentCost;
}

// Function to get Insurance Cost
float getInsurance()
{
	float insuranceCost;
	cout << "Enter the Insurance Cost and Press Enter" << endl;
	cin >> insuranceCost;
	//return result
	return insuranceCost;
}

// Function to get Gas Cost
float getGas()
{
	float gasCost;
	cout << "Enter the gas cost and Press Enter" << endl;
	cin >> gasCost;
	// return result
	return gasCost;
}

// Function to get Oil cost
float getOil()
{
	float oilCost;
	cout << "Enter the oil cost and press Enter" << endl;
	cin >> oilCost;
	// return result
	return oilCost;
}

// Function to get Tires Cost
float getTires()
{
	float tiresCost;
	cout << " Enter the tire cost and press Enter" << endl;
	cin >> tiresCost;
	// return result
	return tiresCost;
}
// Function to get Maintenance cost

float getMaintenance()
{
	float maintenanceCost;
	cout << " Enter the maintenance cost and press Enter" << endl;
	cin >> maintenanceCost;
	// return result
	return maintenanceCost;
}


void showResult(float loanPaymentCost, float insuranceCost, float gasCost, float oilCost, float tiresCost, float maintenanceCost)
{
	//Display all the purchase amount, state tax, county tax, total tax, and total of sale
	cout << "Loan Payment Cost= " << loanPaymentCost << endl;
	cout << "Insurance Cost = " << insuranceCost << endl;
	cout << "Gas Cost = " << gasCost << endl;
	cout << "Oil Cost = " << oilCost << endl;
	cout << "Tires Cost = " << tiresCost << endl;
	cout << "Maintenance Cost= " << maintenanceCost << endl;
}

// Function to calculate total Monthly Costs
float calculateTotalMonthlyCosts(float loanPaymentCost,
 float insuranceCost,
 float gasCost,
	float oilCost,
	float tiresCost,
	float maintenanceCost)

{
	float totalMonthlyCosts;
	
	totalMonthlyCosts = (loanPaymentCost + insuranceCost + gasCost + oilCost + tiresCost + maintenanceCost);

		return totalMonthlyCosts;
}

Last edited on
@SamuelAdams It works! I see what you did there!! I really appreciate the help!!
Hi,

I am pleased you have a solution now :+)

Did you see my PM ? The envelope at the top of the page is hard to see (or remember to look for) For some reason I couldn't reply to your other Topic.


Did you understand what I meant about using const ?

Another thing about topics, try to keep 1 topic going - rather than start a new one about the same subject each time.

Edit:
Although it was good this time - I could reply :+) , maybe that was why you created a new topic - cheers
Last edited on
Topic archived. No new replies allowed.