output returning all zeros instead of calculations

I can't get my output right and I have no idea where I've gone wrong. Any ideas?

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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
 #include <iostream>
#include <string>
using namespace std;

// function prototypes
double chooseMonthlyPremium(double planAParticipant, double planBParticipant, double planCParticipant, double monthlyPremiumCost);
double testMonthlyPremium(double monthlyPremiumCost);
double chooseDisabilityCoverage();
double chooseLongTermCare();
double smokerInfo();
void completePolicyInfo(double monthlyPremiumCost, double disabilityCoverage, double longTermCoverage, double smokerCost, double grossTotal);


int main()
{
	char cont = '\0';
	const char SENTINEL = 'q';
	int userCount = 0;
	double planAParticipant = 0;
	double planBParticipant = 0;
	double planCParticipant = 0;
	double grossTotal= 0.0;	
	double monthlyPremiumCost = 0.0;	
	double disabilityCoverage = 0.0;
	double longTermCoverage = 0.0;	
	double smokerCost = 0.0;
		
	cout << "Welcome to Langdon Life Insurance Inc.  The following program will help calculate your monthly insurance premiums.\n\n";
	system("pause");
		
	while (cont != SENTINEL)
	{
	chooseMonthlyPremium(planAParticipant, planBParticipant, planCParticipant, monthlyPremiumCost);
	testMonthlyPremium(monthlyPremiumCost);
	chooseDisabilityCoverage();
	chooseLongTermCare();
	smokerInfo();
	completePolicyInfo(monthlyPremiumCost, disabilityCoverage, longTermCoverage, smokerCost, grossTotal);
	
	userCount ++;
	
	cout << "Enter \'q'\ to quit or any other charachter to continue: ";
	cin >> cont;

	cout << "Here are your daily totals:\n";
	cout << "Plan A Participants: " << planAParticipant <<"\n";
	cout << "Plan B Participants: " << planBParticipant <<"\n";
	cout << "Plan C Participants: " << planCParticipant <<"\n";
	cout << "Total estimates given: " << userCount <<"\n";
	cout << "The gross total of your estimates is: $" <<grossTotal <<"\n";
	
	system("pause");	
	
	}
}

double chooseMonthlyPremium(double planAParticipant, double planBParticipant, double planCParticipant, double monthlyPremiumCost)
	{
	
	int monthlyPremiumChoice;
	
	cout << "Basic Monthly Premium Choices\n";
	cout << "1. Plan A 	$175.00\n";
	cout << "2. Plan B	$198.00\n";
	cout << "3. Plan C	$225.00\n";
	cout << "Which policy would you like to purchase?\n";
	cin >> monthlyPremiumChoice;

	switch(monthlyPremiumChoice)
	{
	case 1:
			monthlyPremiumCost = 175.00;
			planAParticipant ++;
			return monthlyPremiumCost;
			return planAParticipant;
			break;
	case 2:
			monthlyPremiumCost = 198.00;
			planBParticipant ++;
			return monthlyPremiumCost;
			return planBParticipant;
			break;
	case 3:
			monthlyPremiumCost = 225.00;
			planCParticipant ++;
			return monthlyPremiumCost;
			return planCParticipant;
			break;
	default:
			return 0;
	}	
	}

double testMonthlyPremium(double monthlyPremiumCost)
	{
	double yearlyPremiumBeforeAdditions = 0.0;

	cout << "Your basic monthly premium is " << monthlyPremiumCost <<"\n";
	yearlyPremiumBeforeAdditions = monthlyPremiumCost * 12;
	cout << "Your YEARLY premium cost is "<< yearlyPremiumBeforeAdditions <<"\n";
	return monthlyPremiumCost;
	return yearlyPremiumBeforeAdditions;
	}

double chooseDisabilityCoverage()
	{
	int disabilityOption;
	double disabilityCoverage;

	cout << "Would you like to include disability coverage? 1 for yes, 2 for no\n";
	cin >> disabilityOption;
	
	switch(disabilityOption)
	{
		case '1':
			disabilityCoverage = 0.00;
			return disabilityCoverage;
			break;
	
		case '2':
			disabilityCoverage = 76.00;
			return disabilityCoverage;
			break;	
		default:
			return 0;
	}
	}

double chooseLongTermCare()
	{
	int longTermOption;
	double longTermCoverage;
	
	cout << "Would you like to include Long-Term care? 1 for yes, 2 for no\n";
	cin >> longTermOption;
	
	switch(longTermOption)
	{
		case '1':
			longTermCoverage = 0.00;
			return longTermCoverage;
			break;
		case '2':
			longTermCoverage = 110.00;
			return longTermCoverage;
			break;	
		default:
			return 0;
	}
	}

double smokerInfo()
	{
	int smokerOption;
	double smokerCost;
		
	cout << "Are you a smoker? 1 for yes, 2 for no\n";
	cin >> smokerOption;
	
	switch(smokerOption)
	{
		case '1':
			smokerCost = .05;
			return smokerCost;
			break;
		case '2':	
			smokerCost = 0;
			return smokerCost;
			break;
		default:
			return 0;
	}
	}

void completePolicyInfo(double monthlyPremiumCost, double disabilityCoverage, double longTermCoverage, double smokerCost, double grossTotal)
{
	double smokerPenalty;
	double smokerMonthlyPenalty;
	double totalMonthlyPremium;
		
	smokerPenalty = smokerCost * 100;
	
	cout << "Below is your computed policy information based on the selections you have provided:\n";
	cout << "Monthly Base Premium: $" <<monthlyPremiumCost <<"\n";
	cout << "Disability Coverage: $" << disabilityCoverage <<"\n";
	cout << "Long-Term Care: $" << longTermCoverage <<"\n";
	cout << "Smoker Penalty: "<<smokerPenalty <<" % \n";
	
	if(smokerPenalty != 0)
	{
		smokerMonthlyPenalty = (monthlyPremiumCost + disabilityCoverage + longTermCoverage) * smokerCost;
		totalMonthlyPremium = monthlyPremiumCost + disabilityCoverage + longTermCoverage + smokerMonthlyPenalty;
		grossTotal = grossTotal + totalMonthlyPremium;
	}
	else
		totalMonthlyPremium = monthlyPremiumCost + disabilityCoverage + longTermCoverage;
		grossTotal = grossTotal + totalMonthlyPremium;
	
	cout << "Total Monthly Premium: $" << totalMonthlyPremium<<"\n";	
	
	
}
You can't use two return statements in a switch, and your defalut statement shouldn't return 0. It should do something to deal with the fact that incorrect input was entered.
Last edited on
Ok I fixed all of that, but still getting zeros....

#include <iostream>
#include <string>
using namespace std;

// function prototypes
double chooseMonthlyPremium(double planAParticipant, double planBParticipant, double planCParticipant, double monthlyPremiumCost);
double testMonthlyPremium(double monthlyPremiumCost);
double chooseDisabilityCoverage();
double chooseLongTermCare();
double smokerInfo();
void completePolicyInfo(double monthlyPremiumCost, double disabilityCoverage, double longTermCoverage, double smokerCost, double grossTotal);


int main()
{
char cont = '\0';
const char SENTINEL = 'q';
int userCount = 0;
double planAParticipant = 0;
double planBParticipant = 0;
double planCParticipant = 0;
double grossTotal= 0.0;
double monthlyPremiumCost = 0.0;
double disabilityCoverage = 0.0;
double longTermCoverage = 0.0;
double smokerCost = 0.0;

cout << "Welcome to Langdon Life Insurance Inc. The following program will help calculate your monthly insurance premiums.\n\n";
system("pause");

while (cont != SENTINEL)
{
chooseMonthlyPremium(planAParticipant, planBParticipant, planCParticipant, monthlyPremiumCost);
testMonthlyPremium(monthlyPremiumCost);
chooseDisabilityCoverage();
chooseLongTermCare();
smokerInfo();
completePolicyInfo(monthlyPremiumCost, disabilityCoverage, longTermCoverage, smokerCost, grossTotal);

userCount ++;

cout << "Enter \'q'\ to quit or any other charachter to continue: ";
cin >> cont;

cout << "Here are your daily totals:\n";
cout << "Plan A Participants: " << planAParticipant <<"\n";
cout << "Plan B Participants: " << planBParticipant <<"\n";
cout << "Plan C Participants: " << planCParticipant <<"\n";
cout << "Total estimates given: " << userCount <<"\n";
cout << "The gross total of your estimates is: $" <<grossTotal <<"\n";

system("pause");

}
}

double chooseMonthlyPremium(double planAParticipant, double planBParticipant, double planCParticipant, double monthlyPremiumCost)
{

int monthlyPremiumChoice;

cout << "Basic Monthly Premium Choices\n";
cout << "1. Plan A $175.00\n";
cout << "2. Plan B $198.00\n";
cout << "3. Plan C $225.00\n";
cout << "Which policy would you like to purchase?\n";
cin >> monthlyPremiumChoice;

switch(monthlyPremiumChoice)
{
case 1:
monthlyPremiumCost = 175.00;
planAParticipant ++;
break;
case 2:
monthlyPremiumCost = 198.00;
planBParticipant ++;
break;
case 3:
monthlyPremiumCost = 225.00;
planCParticipant ++;
break;
default:
cout << "Invalid Selection";
}
return monthlyPremiumCost;
return planAParticipant;
return planBParticipant;
return planCParticipant;
}

double testMonthlyPremium(double monthlyPremiumCost)
{
double yearlyPremiumBeforeAdditions = 0.0;

cout << "Your basic monthly premium is " << monthlyPremiumCost <<"\n";
yearlyPremiumBeforeAdditions = monthlyPremiumCost * 12;
cout << "Your YEARLY premium cost is "<< yearlyPremiumBeforeAdditions <<"\n";
return monthlyPremiumCost;
return yearlyPremiumBeforeAdditions;
}

double chooseDisabilityCoverage()
{
int disabilityOption;
double disabilityCoverage = 0.0;

cout << "Would you like to include disability coverage? 1 for yes, 2 for no\n";
cin >> disabilityOption;

switch(disabilityOption)
{
case 1:
disabilityCoverage = 0.00;
break;

case 2:
disabilityCoverage = 76.00;
break;
default:
cout << "Invalid selection.";
}
return disabilityCoverage;
}

double chooseLongTermCare()
{
int longTermOption;
double longTermCoverage = 0.0;

cout << "Would you like to include Long-Term care? 1 for yes, 2 for no\n";
cin >> longTermOption;

switch(longTermOption)
{
case 1:
longTermCoverage = 0.00;
break;
case 2:
longTermCoverage = 110.00;
break;
default:
cout << "Invalid selection";
}
return longTermCoverage;
}

double smokerInfo()
{
int smokerOption;
double smokerCost = 0.0;

cout << "Are you a smoker? 1 for yes, 2 for no\n";
cin >> smokerOption;

switch(smokerOption)
{
case 1:
smokerCost = .05;
break;
case 2:
smokerCost = 0;
break;
default:
cout << "Invalid selection";
}
return smokerCost;
}

void completePolicyInfo(double monthlyPremiumCost, double disabilityCoverage, double longTermCoverage, double smokerCost, double grossTotal)
{
double smokerPenalty;
double smokerMonthlyPenalty;
double totalMonthlyPremium;

smokerPenalty = smokerCost * 100;

cout << "Below is your computed policy information based on the selections you have provided:\n";
cout << "Monthly Base Premium: $" <<monthlyPremiumCost <<"\n";
cout << "Disability Coverage: $" << disabilityCoverage <<"\n";
cout << "Long-Term Care: $" << longTermCoverage <<"\n";
cout << "Smoker Penalty: "<<smokerPenalty <<" % \n";

if(smokerPenalty != 0)
{
smokerMonthlyPenalty = (monthlyPremiumCost + disabilityCoverage + longTermCoverage) * smokerCost;
totalMonthlyPremium = monthlyPremiumCost + disabilityCoverage + longTermCoverage + smokerMonthlyPenalty;
grossTotal = grossTotal + totalMonthlyPremium;
}
else
totalMonthlyPremium = monthlyPremiumCost + disabilityCoverage + longTermCoverage;
grossTotal = grossTotal + totalMonthlyPremium;

cout << "Total Monthly Premium: $" << totalMonthlyPremium<<"\n";
}
The problem is that you pass variables like planAParticipant to the functions by value, which means that the function holds its own copy of the variable. It doesn't change the original one, which is what you want.
What you need to do is pass them by reference: http://www.learncpp.com/cpp-tutorial/73-passing-arguments-by-reference/
Thanks so much! Now it works!
Topic archived. No new replies allowed.