Help With Monthly Vehicle Expense Program

I'm trying to create a program that takes an input file that contains miles driven for the year, car miles per gallon, cost of gas per gallon,
amount spent on maintenance for the year, and car insurance premium for the year and calculates the total monthly costs for the vehicle. The program must use the functions and parameters that it contains. I am very new to c++ and I don't think I'm on the right track by any means. I'd appreciate it very much if someone would be able to help me. Thank you.

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
//Thomas Allicino  2/18/16
#include <iostream>
#include <fstream>
#include <iomanip>

using namespace std;

double MonthlyGasCost(double milesPerYear, double carMilesPerGallon, double gasCostPerGallon)
{
	double gasCostPerMonth, milesPerMonth, gallonsPerMonth;

	milesPerMonth == milesPerYear / 12;

	gallonsPerMonth == milesPerMonth * carMilesPerGallon;

	gasCostPerMonth == gallonsPerMonth * gasCostPerGallon;

	return gasCostPerMonth;

}

double MonthlyMaintenanceCost(double mainYearAmt)
{
	double mainCostPerMonth;

	mainCostPerMonth == mainYearAmt / 12;

	return mainCostPerMonth;

}

double MonthlyPremiumCost(double yearPremium)
{
	double insCostPerMonth;

	insCostPerMonth == yearPremium / 12;

	return insCostPerMonth;

}

void TotalCostPerMonth(double gasCostPerMonth, double insCostPerMonth, double mainCostPerMonth, double totalCost)
{
	totalCost == gasCostPerMonth + insCostPerMonth + mainCostPerMonth;
}

int main()
{
	double milesPerYear, carMilesPerGallon, gasCostPerGallon, mainYearAmt, yearPremium;
	double totalCost, mainCostPerMonth, insCostPerMonth, gasCostPerMonth;

	ifstream infile;
	infile.open("GasCosts.txt");
	infile >> milesPerYear >> carMilesPerGallon >> gasCostPerGallon >> mainYearAmt >> yearPremium;

	MonthlyGasCost(milesPerYear, carMilesPerGallon, gasCostPerGallon);
	MonthlyMaintenanceCost(mainCostPerMonth);
	MonthlyPremiumCost(insCostPerMonth);
	TotalCostPerMonth(gasCostPerMonth, insCostPerMonth, mainCostPerMonth, totalCost);
}

The are a few mistakes:
line 12: milesPerMonth == milesPerYear / 12;
The == operator is for comparison, = is used for assignment.
Same mistake on other lines.

You also need to output the results.
1
2
cout << "Monthly gas cost: " << MonthlyGasCost(milesPerYear, carMilesPerGallon, gasCostPerGallon);
// etc. 
Line 50: gasCostPerMonth is uninitialized.

Line 56: You call MonthlyGasCost, but you ignore the result.

Line 59: You pass gasCostPerMonth (garbage) to TotalCostPerMonth().

Same problem exists with your other functions.

Line 58: You call MonthlyPremiumCost passing insCostPerMonth, while MonthlyPremiumCost is expecting yearPremium.

Line 14: Your calculation is incorrect. gallons = miles / mpg.
Topic archived. No new replies allowed.