Please help me with this run time error

i get this run time error when i try to run my program

1
2
3
1>c:\users\administrator\desktop\project3\project3\familybudget.cpp(42): warning C4700: uninitialized local variable 'monthlypay' used
1>c:\users\administrator\desktop\project3\project3\familybudget.cpp(43): warning C4700: uninitialized local variable 'savings' used
1>c:\users\administrator\desktop\project3\project3\familybudget.cpp(44): warning C4700: uninitialized local variable 'expecliving' used



this 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#include <iostream>
#include <iomanip>

using namespace std;

// Function prototypes

float calclivingexpen(float);
float calcmonthlypay(float, float);
float calcsavings(float, float, float, float);
void displayOutput(float, float, float, float, float, float, float);

// End Prototypes

int main ()
{
	//Local Declarations

	float idnumber, numfamily, income, totaldebt;
	float expecliving;
	float monthlypay;
	float savings;

	// Program Input data

	cout << "Enter Id Number: ";
	cin >> idnumber;
	cout << "Enter Number of family members: ";
	cin >> numfamily;
	cout << "Enter Amount of Income: ";
	cin >> income;
	cout << "Enter Total Debt Amount: ";
	cin >> totaldebt;

	calclivingexpen(numfamily);
	calcmonthlypay(monthlypay, totaldebt);
	calcsavings(savings, numfamily, income, totaldebt);
	displayOutput(idnumber, numfamily, income, totaldebt, expecliving, monthlypay, savings);
	

	return 0;
}
// End Main

float calclivingexpen(float numfamily)
{
	// Local Declarations

	const float perperson = 50000.00;

	float expecliving;

		expecliving = (numfamily * perperson);

		return expecliving;
}

float calcmonthlypay(float monthlypay, float totaldebt)
{
	
	monthlypay = (totaldebt/12);

	return monthlypay;
}

float calcsavings(float savings, float famsize, float income, float totaldebt)
{

	savings = (famsize * 0.02) * (income - totaldebt);

	return savings;
}




void displayOutput(float idnumber, float numfamily, float income, float totaldebt, float expecliving, float monthlypay, float savings)
{
	// Program statements

	cout << "The id number is: " << idnumber << endl;
	cout << "The number of family is: " << numfamily << endl;
	cout << "The total income is: " << income << endl;
	cout << "The total debt is: " << totaldebt << endl;
	cout << "The expected living is: " << expecliving << endl;
	cout << "The monthly payment is: " << monthlypay << endl;
	cout << "Savings is: " << savings << endl;


	return;
}


You have used those three variables without initializing / assigning any value .

Just initialize it to zero . OR dont bother passing them in the function when the function
itself is creating them .
Those are not runtime errors. They are compile-time warnings.

They warn you that you are using some variables without having given them a value.

The crux of your problems is that you do not understand how variables are passed to and from functions. For example, when you call the function calcmonthlypay in your code, no change is made to the value monthlypay in your main function.

You need to read up on how to use functions, and the methods of passing variables; pass-by-value (including pass-by-pointer, which is a particular use of pass-by-value) and pass-by-reference, and how to use the returned value.
Last edited on
Thanks for the quick reply, i did initialize those three values to '0', but if i do that then the output comes as '0'.

I am new to c++ and I'm just trying my best to make this program work.
Topic archived. No new replies allowed.