Can you check what's wrong with my code? HELP

I need help getting my code to run.

The population of a town A is less than the population of town B. However, the population of town A is growing faster than the population of town B. Write a program that prompts the user to enter the population and growth rate of each town. The program outputs after how man years the population of town A will be greater than or equal to the population of town B and the populations of both the towns at the same time.
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

#include<iostream> 
using namespace std; 

int main() 
{ 
double popA, popB, rateA, rateB, newpopA, newpopB; 
int numOfYears = 0; 

cout << "Enter population for town A: "; 
cin >> popA; 
cout << "Enter population for town B (Must be larger than town A): "; 
cin >> popB; 

if (popA < popB) 
{ 
cout << "Enter the growing rate of town A: "; 
cin >> rateA; 
cout << "Now enter the growing rate of Town B: "; 
cin >> rateB; 

if (rateA <= rateB) 
cout << "Invalid "; 


else if (rateA > rateB) 
{ 
while (newpopA < newpopB) 

cout << "Population A: " << newpopA << endl; 
newpopA = (popA * (rateA / 100.0)) + popA; 

cout << "Population B: " << newpopB << endl; 
newpopB = (popB * (rateB / 100.0)) + popB; 
numOfYears++; 

} 
} 
if (popA > popB) 
cout << "Your input was invalid"; 
return 1; 

}
You need to swap line 31 and 30
and line 34 and 33

You are using a variable that has not been initialized
Topic archived. No new replies allowed.