Display output function problem

Mar 13, 2012 at 4:45pm
So i need to create a program to calculate some amount of number using function, i'm able to do it but my problem is at the display function, i'm not really sure why i don't get my output. here is the code, thanks:


#include <iostream>
#include <iomanip>

using namespace std;

// Function prototypes

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

// End Prototypes

int main (void)
{
//Local Declarations

float idnumber, numfamily, income, totaldebt;

// 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;

return idnumber, numfamily, income, totaldebt;
}
// End Main

float calclivingexpen(float numfamily)
{
// Local Declarations

const float perperson = 50000.00;

float expecliving;

expecliving = (numfamily * perperson);

return expecliving;
}



void displayOutput(float expecliving)
{
// Program statements

cout << "The amount of living expenses is: " << expecliving << endl;

return;
}



Mar 13, 2012 at 5:13pm
What do you expect line return idnumber, numfamily, income, totaldebt;? It really does noting. You need to call calclivingexpen and displayOutput yourself. Maybe you should see http://cplusplus.com/doc/tutorial/functions/
Mar 13, 2012 at 5:14pm
You don't seem to be calling any of your user defined functions (calclivingexpen or displayOutput) from within your main function.

Your main function alse has return type [int] but you are trying to return all the floats defined (idnumber, numbfamily, ...). You cannot return multiple values for a function via it's return type, ie you can only return a ingle value and it should be an int value indicating program success or failure, and should have nothing to do with the variables you declared.

Also please try using code tags (from Format options) when posting code.
Mar 13, 2012 at 5:22pm
you can define the structure as
1
2
3
4
5
6
7
struct details
{
	int idnumber;
	int  numfamily;
	float income;
	float totaldebt;
	};


and setting the value of the structure and returning the structure .
Mar 18, 2012 at 11:09pm
Thanks for the reply, i believe i added the functions to my main, but i get some errors:

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



this is my source 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
#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, expecliving, monthlypay, 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;
}


BTW, my teacher told me to input all my info on main, this is why i have all the cin statements in main. Thanks
Topic archived. No new replies allowed.