Need help with c++

I am new to programming and I have a hard time writing some programs. I am currently stuck at this point. I will post the code that I currently have.

This program is designed to analyze the growth of two cities. Each city has a starting population and annual growth rate. The smaller city has the larger growth rate (required). Show the comparative populations of each city year by year until the smaller city has grown larger than the bigger city.

As an example, Dogville has a population of 5000 growing at 20% annually while Cattown has a population of 7000 growing at 10% annually. The projected populations are:
Year Dogville Cattown
1 6000 7700
2 7200 8470
3 8640 9317
4 10368 10249

Code:


#include <iostream>
#include <iomanip>
using namespace std;
int main ()
{
int stpop = 0;
int btpop = 0;
double strate =0;
double btrate =0;

do
{
cout << "Enter the starting population for the small town:" << endl;
cin >> stpop;
cout << "Enter the starting population for the big town:" << endl;
cin>> btpop;
}
while (stpop > btpop);
do
{
cout << "Enter the growth rate for the small town" << endl;
cin >> strate;
cout << "Enter the growth rate for the big town" << endl;
cin >> btrate;
}
while (strate < btrate);




system("pause");
return 0;
}
can anyone help?
Are you looking for something like this?

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
#include <iostream>

using namespace std;

int main()
{
    int dvpop = 0;
    int ctpop = 0;
    int counter = 0;
    float dvgrowth = 0;
    float ctgrowth = 0;

    cout << "Enter starting population of Dogville " << endl;
    cin >> dvpop;
    cout << endl;
    cout << "Enter the starting population of Cattown " << endl;
    cin >> ctpop;
    cout << endl;

    cout << "Enter growth rate for Dogville " << endl;
    cin >> dvgrowth;
    dvgrowth /= 100;
    cout << endl;

    cout << "Enter the growth rate for Cattown " << endl;
    cin >> ctgrowth;
    ctgrowth /= 100;
    cout << endl;

    cout << "Year" << " " << "Dogville" << " " << "Cattown" << endl;
    cout << "---------------------------------------------" << endl;

    while (dvpop < ctpop)
    {
        dvpop += (dvpop * dvgrowth);
        ctpop += (ctpop * ctgrowth);
        counter += 1;

        cout << counter<<" " << dvpop <<" " << ctpop << endl;
    }
}
Last edited on
Yes it was. I will have to tweak it a little but you have helped me tremendously. I now have my program working. Thank you very much
You're very welcome.
You were 95% there anyway. Good going!
Topic archived. No new replies allowed.