Asking for information twice

I am suppose to be writing a code that calculates the future population based on user input. Below is what I have so far. The problem I am having is that my information gets asked twice and I can't figure out why. Any tips would be appreciated!
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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226

#include <iostream>
#include <iomanip>
#include <cmath>

using namespace std;

char selectOption ();
void askOption ();
void getPPnoInOut(_int64 &PopulationStart, int &Birthrate, int &Deathrate, int &Yearstocalc);
void calcAndPrintPopulationChange (_int64 PopulationStart, int Birthrate, int Deathrate, int Yearstocalc);
void calcAndPrintPopulationChange (_int64 PopulationStart, int Birthrate, int Deathrate, int Inmigration, int Outmigration, int Yearstocalc);
void getPPwithInOut (_int64 &PopulationStart, int &Birthrate, int &Deathrate, int &Inmigration, int &Outmigration, int &Yearstocalc);



int main ()
{
	char option;
	_int64 populationStartSize;
	int annualBirthRate;
	int annualDeathRate;
	int inMigration;
	int outMigration;
	int numberOfYears;

	option = selectOption(); //exectues select option & ask option

	switch (option)
	{
	case 'P': //Pull in/execute vales from PP without in and out
		getPPnoInOut (populationStartSize, annualBirthRate, annualDeathRate, numberOfYears);

		calcAndPrintPopulationChange (populationStartSize, annualBirthRate, annualDeathRate, numberOfYears);

		break;

	case 'C': //Pull in/execute values from PP with In and out
		
		getPPwithInOut (populationStartSize, annualBirthRate, annualDeathRate, numberOfYears, inMigration, outMigration);

		calcAndPrintPopulationChange (populationStartSize, annualBirthRate, annualDeathRate, inMigration, outMigration, numberOfYears);

		break;
	case 'E': exit (0);
	}
}

void calcAndPrintPopulationChange (_int64 PopulationStart, int Birthrate, int Deathrate, int Yearstocalc)
{
	_int64 populationStartSize;
	int annualBirthRate;
	int annualDeathRate;
	int inMigration;
	int outMigration;
	int numberOfYears;
	int newpop;

	getPPnoInOut (populationStartSize, annualBirthRate, annualDeathRate, numberOfYears);

		cout << "Starting population Size: " << populationStartSize << endl;
		cout << "Birth Rate: " << annualBirthRate << endl;
		cout << "Death Rate: " << annualDeathRate << endl;
		cout << "Number of Years calculated: " << numberOfYears << endl;
		
		for (int i = 0; i < numberOfYears; i++)
		{
			newpop = populationStartSize * (1+annualBirthRate/100)-(annualDeathRate/100*populationStartSize);
		}

		cout << "In " << numberOfYears << " years, the population will be " << newpop << "." << endl;
}

void calcAndPrintPopulationChange (_int64 PopulationStart, int Birthrate, int Deathrate, int Inmigration, int Outmigration, int Yearstocalc) //**This function is not complete yet.
{
	_int64 populationStartSize;
	int annualBirthRate;
	int annualDeathRate;
	int inMigration;
	int outMigration;
	int numberOfYears;
	int newpop;

	getPPwithInOut (populationStartSize, annualBirthRate, annualBirthRate, numberOfYears, inMigration, outMigration);
		
	cout << "Starting population Size: " << populationStartSize << endl;
		cout << "Birth Rate: " << annualBirthRate << endl;
		cout << "Death Rate: " << annualDeathRate << endl;
		cout << "In-Migration Rate: " << inMigration << endl;
		cout << "Out-Migration Rate: " << outMigration << endl;
		cout << "Number of Years calculated: " << numberOfYears << endl;

		for (int i = 0; i < numberOfYears; i++)
		{
			newpop = populationStartSize * (1+annualBirthRate/100)-(annualDeathRate/100*populationStartSize);
		}

		cout << "In " << numberOfYears << " years, the population will be " << newpop << "." << endl;
}

void getPPnoInOut(_int64 &PopulationStart, int &Birthrate, int &Deathrate, int &Yearstocalc)
{
	cout << "Input the starting population: "; //population
	cin >> PopulationStart; 
	while (PopulationStart < 1)
	{
		cout << "Whoops! Population size must be larger than 0" << endl;
		cout << "Input the starting population: " << endl;
		cin >> PopulationStart;
	}
	
	cout << endl <<"Input the birth rate as an integer %: "; //birth rate
	cin >> Birthrate;
		while (Birthrate < 0 || Birthrate > 100)
		{
			cout << "Whoops! The Birth Rate must be greater that 0 but less than 100" << endl;
			cout << "Input the birth rate as an interger %: ";
			cin >> Birthrate;
		}
	
	cout << endl << "Input the death rate as an integer %: "; //death rate
	cin >> Deathrate;
		while (Deathrate < 0 || Deathrate > 100)
		{
			cout << "Whoops! The Death Rate must be greater that 0 but less than 100" << endl;
			cout << "Input the death rate as an integer %: ";
			cin >> Deathrate;
		}

	cout << endl << "Input the number of years for the calculation as an integer: "; //number of years
	cin >> Yearstocalc;
		while (Yearstocalc < 0 || Yearstocalc > 100)
		{
			cout << "Whoops! The number of years must be greater that 0 but less than 100" << endl;
			cout << "Input the number of years for the calculation as an integer: ";
			cin >> Yearstocalc;
		}
}

void getPPwithInOut (_int64 &PopulationStart, int &Birthrate, int &Deathrate, int &Yearstocalc, int &Inmigration, int &Outmigration)
{
	cout << "Input the starting population: "; //population
	cin >> PopulationStart; 
	while (PopulationStart < 1)
	{
		cout << "Whoops! Population size must be larger than 0" << endl;
		cout << "Input the starting population: " << endl;
		cin >> PopulationStart;
	}
	
	cout << endl <<"Input the birth rate as an integer %: "; //birth rate
	cin >> Birthrate;
		while (Birthrate < 0 || Birthrate > 100)
		{
			cout << "Whoops! The Birth Rate must be greater that 0 but less than 100" << endl;
			cout << "Input the birth rate as an interger %: ";
			cin >> Birthrate;
		}
	
	cout << endl << "Input the death rate as an integer %: "; //death rate
	cin >> Deathrate;
		while (Deathrate < 0 || Deathrate > 100)
		{
			cout << "Whoops! The Death Rate must be greater that 0 but less than 100" << endl;
			cout << "Input the death rate as an integer %: ";
			cin >> Deathrate;
		}

	cout << endl << "Input the number of years for the calculation as an integer: "; //number of years
	cin >> Yearstocalc;
		while (Yearstocalc < 0 || Yearstocalc > 100)
		{
			cout << "Whoops! The number of years must be greater that 0 but less than 100" << endl;
			cout << "Input the number of years for the calculation as an integer: ";
			cin >> Yearstocalc;
		}

	cout << endl << "Input the In-migration rate as an integer %: ";
	cin >> Inmigration;
		while (Inmigration < 0 || Inmigration > 100)
		{
			cout << "Whoops! The In-migration rate must be greater than 0 but less than 100" << endl;
			cout << "Input the In-migration rate as an integer %: ";
			cin >> Inmigration;
		}

	cout << endl << "Input the Out-migration rate as an integer %: ";
	cin >> Outmigration;
		while (Outmigration < 0 || Outmigration > 100)
		{
			cout << "Whoops! The Out-migration rate must be greater than 0 but less than 100" << endl;
			cout << "Input the Out-migration rate as an integer %: ";
			cin >> Outmigration;
		}
		
}

void askOption ()
{
	cout << "Please select from the following options" << endl;
	cout << /* need to setw << */ "Select 'P' for population growth without considering in or out-migration." << endl;
	cout << /* need to setw << */ "Select 'C' for populating growth with in and out migration to be considered." << endl;
	cout << /* need to setw << */ "Select 'E' to clost the program." << endl;
	cout << /* need to setw << */ "Please note that the program is case sensitive!" << endl;
	cout << /* need to setw << */ "Option (P, C, or E): " << endl;

	return;
}

char selectOption ()
{
	char option;

	cout << "Welcome to the Population Growth Program" << endl;
	askOption ();
	cin >> option;

	while (option != 'P' && option != 'C' && option != 'E')
	{
		cout << "Whoops! option must be either P, C, or E." << endl;
		askOption ();
		cin >> option;
	}

	return option;
}
Remove lines 59 and 84. Also, your getPPnoInOut and getPPwithInOut are practically the same. You should just call getPPnoInOut in your getPPwithInOut, then add the rest.
I thought that at first but then I run into the issue of lines 61 - 64 not being initialized. I have to call that function in order to get the user inputs for those values.

And just to make sure I did this correctly (thanks for the tip by the way):
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
 void getPPwithInOut (_int64 &PopulationStart, int &Birthrate, int &Deathrate, int &Yearstocalc, int &Inmigration, int &Outmigration)
{
	getPPnoInOut (PopulationStart, Birthrate, Deathrate, Yearstocalc); 
        cout << endl << "Input the In-migration rate as an integer %: ";
	cin >> Inmigration;
		while (Inmigration < 0 || Inmigration > 100)
		{
			cout << "Whoops! The In-migration rate must be greater than 0 but less than 100" << endl;
			cout << "Input the In-migration rate as an integer %: ";
			cin >> Inmigration;
		}

	cout << endl << "Input the Out-migration rate as an integer %: ";
	cin >> Outmigration;
		while (Outmigration < 0 || Outmigration > 100)
		{
			cout << "Whoops! The Out-migration rate must be greater than 0 but less than 100" << endl;
			cout << "Input the Out-migration rate as an integer %: ";
			cin >> Outmigration;
		}
		
}
Your getPPnoInOUt and getPPwithInOut have their parameters passed by reference. Just do the same with your calc functions.
Whoops! My reply didn't go through. I ended up submitting my assignment last night incomplete - I did the best I could. I still would like to know what my error was though. I tried doing what you said fg109 but I ended up getting this error when building:
1>CS1400_Assignment8.obj : error LNK2019: unresolved external symbol "void __cdecl calcAndPrintPopulationChange(__int64,int,int,int)" (?calcAndPrintPopulationChange@@YAX_JHHH@Z) referenced in function _main
1>CS1400_Assignment8.obj : error LNK2019: unresolved external symbol "void __cdecl calcAndPrintPopulationChange(__int64,int,int,int,int,int)" (?calcAndPrintPopulationChange@@YAX_JHHHHH@Z) referenced in function _main

Any suggestion/critiques on the way I wrote my program would be awesome.
I am horrible at reading error messages. All I can tell is that it's a linker error.

A quick google search seems to tell me that it means there is no function definition for your function prototype. In your case, that probably means you added the & symbols to the function definitions but not the prototypes.
Topic archived. No new replies allowed.