Uninitalized local variables

So I believe the problem I am having is that I've been looking at my code for so long that it is starting to look like Greek. The error I am getting is in this first bit of code Error C4700: uninitialized local variable 'money', 'taxAmount', 'grossPay'



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
double CalculateNetPay(double, double)
{
	double grossPay, taxAmount, netPay;

	netPay = grossPay - taxAmount;
	
	cout << netPay << endl;

	return 0;
}

string FormatMoney(double)
{
	double money;

	cout << setprecision(2) << money << endl;
			
	return 0;
}


This is the full code but I just wanted it to be as clear as possible as to where the error is. As you will see the error is in the report2.cpp file but I have included the report2.h as well. Neither of these is where my main is located. But I cannot write a main until this works. And yes I do have to break them up into these file types.(UGH!!)


report2.cpp
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
#include "report2.h"
#include <iostream>
#include <string>
#include <iomanip>

using namespace std;
using namespace report2;

void PayrollReport(string, string)
{
	
	string infile, outfile;
	cout << "Open file " << infile << endl;
	cout << "Save file " << outfile << endl;

}

double CalculateNetPay(double, double)
{
	double grossPay, taxAmount, netPay;

	netPay = grossPay - taxAmount;
	
	cout << netPay << endl;

	return 0;
}


string FormatMoney(double)
{
	double money;

	cout << setprecision(2) << money << endl;
			
	return 0;
}



report2.h
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
#include <iostream>
#include <string>

using namespace std;

namespace report2
{
	//Generates an employee payroll report according to the format described 
	//in the Employee Payroll Report section below. The infile parameter is 
	//the name of the file that contains the input data. The outfile parameter 
	//is the name of the file where the report should be written to. You should 
	//use both the function from the static library that your were given and the 
	//functions that you wrote to produce the report. For example, use the 
	//FormatMoney function to create a string version of a dollar amount from 
	//a double. Use single tax rate for all employees.

	void PayrollReport(string infile, string outfile);

	//Calculates the net pay. The net pay is the gross pay minus tax amount.

	double CalculateNetPay(double grossPay, double taxAmount);

	//Takes a money amount as a double and then returns that number as a formatted 
	//money string.For example, if the value 50.748 is passed into the function it 
	//should return $50.75. The number should be ROUNDED to two decimal places.
	//Hint: Use a stringstream to do the formatting. It works very similar to a cout 
	//output stream with respect to formatting.You will need to lookup how to use it.

	string FormatMoney(double amount);
}


Thanks for your help in advanced!
The error message you are getting seems very clear and concise. You have local variables which are not initialised. Ok maybe it is the unintialised part that you don't understand? It simply means they have not been assigned an initial value before being used in the expression

So to fix, assign each variable an initial value
Oh God! I'm so dumb sometimes it is scary. Yes, you would be 100% correct.
Topic archived. No new replies allowed.