population counter problem

i have been interested in the game spore thats coming out soon and, i wanted to make my own text based spore game but i cant get it to count out the population growth per day the logic seems fine to me but the problem might be near the while loop can some show me whats wrong.



#include<iostream>
#include<iomanip>

using namespace std;
int main()

{

int pop,days,total;
//float incres;


//user gives the size of the pop
cout<<"please enter the number of population: ";
cin >>pop;

///////////////////////////////
int space = 1;

while(space <= 2)
{
cout <<""<<endl;
space++;
}
////////////////////////////////


if(pop <= 1)

{
cout<<"Error you are doing it wrong, need at least 2 population"<<endl;
system("pause");
system ("CLS");
return main();

}


//the user inputs the number of days
cout<<"now please enter the the number of days: ";
cin >>days;


if(days <= 1)

{
cout<<"Error you are doing it wrong, need at least 1 day"<<endl;
system("pause");
system ("CLS");
return main();

}



//the population incress on a loop as precentige


cout<<"days population a day"<<endl;
cout<<"-----------------------------"<<endl;


while (days <= pop)
{


days++;

cout << days <<"\t\t%"<<(days * days)<< endl;

}

total = days * pop;

cout <<"the end population is %"<<total<<endl;


return 0;

}
Plz use [c0de][/c0de] tags and indentation on your code...then I'll look at it.
Hi, there are a coupel of things that need fixing, from what I can tell (using # format would make things easier).

First is in your logic for entering the varaibles. You have used return main();. AFAIK this will recursivly call main() (as you are in main()).
A better solution woudl be to have the two data entry parts as simple functions
EG;
1
2
3
4
5
6
int enterPop()
{
   cout<<"please enter the number of population: ";
   cin >>pop;
   return pop;
}

then in main()
1
2
3
4
5
6
7
8
do
{
   pop = enterPop();
   if (pop<2)
   { 
       cout<<"Error you are doing it wrong, need at least 2 population"<<endl;
   }
} while (pop<2);


Secondly the population output loop should be
1
2
3
4
5
for (int currentDay = 1; currentDay <=days; currentDay++)
//Loop from 1 to number of days
{
   //Calculations here
}
Topic archived. No new replies allowed.