Mucking about (should say practising what I've learn't), and made my version of the rabbits practice program. It's not totally finished but it's my first draft and it's working. Before continueing, I'd like a code review please to tell me whats not correctly done or how I could improve my coding? System pause, I know, and it will be out later on.
Here's my code
#include <iostream>
#include <stdlib.h>
using namespace std;
int main()
{
int mr = 1, fr = 1, br = 0; //mr = male rabbits //fr = female rabbits //br = baby rabbits
int pr = 0; //pr = pregnant rabbits
int total = 0;
int temp = 0;
int flag1 = 0;
while (total <= 1000){
// one off population cull
if (total >=500 && flag1 == 0)
{
cout << "Disease strikes the colony!" << endl;
flag1 = 1;
mr = mr / 4;
fr = fr / 4;
br = br / 4;
pr = 0;
}
if (br > 0) //if any babies
{
temp = br / 2;
mr = mr + temp; //adds 1 to male population
fr = fr + temp; //adds 1 to female pop
br = 0;
temp = 0; //resets temp value to 0
}
if (pr > 0) //if any rabbits pregas
{
br = pr * 2; //2 babies per pregnant rabbit
pr = 0; //resets pregas to 0
}
else
if (mr == fr)
pr = fr; //puts each female pregnant
cout << "There is " << mr << " male rabbit" << endl;
cout << "There is " << fr << " female rabbit" << endl;
cout << "Babies born x " << br << endl;
cout << pr << " Female is now pregnant" << endl;
total = mr + fr + br;
cout << "Total Rabbits = " << total << "\n" << endl;
} //while loop closing brace
system("PAUSE");
return 0;
}
Thanks in advance
Leppie