#include <iostream>
#include <iomanip>
#include <string>
usingnamespace std;
int main()
{
string city1, city2;
int pop1, pop2, year = 1;
double rate1, rate2;
cout<< "Please enter town A's name: ";
cin>> city1;
cout<< "Please enter Town B's name: ";
cin>> city2;
cout<< "Please Enter the population of town A: ";
cin>> pop1;
cout<< "Please Enter the population of town B (must be larger than town A's): ";
cin>> pop2;
if (pop1 < pop2)
{
cout<< "Please enter the growth rate of town A: ";
cin>> rate1;
cout<< "Please enter the growth rate of town B (must be less than Town A's): ";
cin>> rate2;
if (rate1 <= rate2)
{
cout<< "ERROR:Growth Rate of Town A must be more than Town B's ";
cin.ignore(2);
return 1;
}
elseif (rate1 > rate2)
{
cout << endl << left << setw(7) << "Year" << setw(20) << city1 << city2 << endl;
while (pop1 < pop2)
{
cout << left << setw(7) << year << setw(20) << pop1 << pop2 << endl;
pop1 += (pop1 * rate1);
pop2 += (pop2 * rate2);
year++;
}
cout << left << setw(7) << year << setw(20) << pop1 << pop2 << endl;
}
}
else
{
cout << "ERROR: Town A's population must be less than town B" << endl;
}
cin.ignore(2);
return 0;
}
Moschops, I'm sorry. I realize it's counter-productive to this forum's mission but I just want to be on the safer side. Even though I came here with my original code (and 90% of it correctly coded), I just don't want to get into any sort of trouble. I hope you understand where I'm coming from.
It should not be a problem as I did not write this code, I only fixed some problems. And You can edit your code by changing < to > in for loop :D. And if you ask for help in forum you most know it will stay here :D