// i dont know why the part below bunny class doesnt work properly help line: 223 i allocated a class array but i can figure out why it doesnt work

#include "stdafx.h"
#include <iostream>
#include <ctime>
#include <string>
int p[100]; // global varialbe 
int times=0,last=0;


void ruleta()
{
	for (int lll=-10,nnn=1;lll<=99;nnn++)				//it has to increase by 10
	{
		lll+=10;
		if (lll > 99)
			break;
		for (int iii=0;iii<=9;iii++)
			p[lll+iii]=(nnn) + (10*iii);
		
	}
}


int random2()
{
	int x;
	x=time(0)-1302141300;
		while (x>10)
			x-=10;		
return x;
}

int random()	//if any problem check this function if statement
{
	int ranNum=random2();
	
	int z=ranNum+last;

	if (z > 100)
		z=z-99;

	last=z;
return p[z-1];
}									//RANDOM STUFF ABOVE//
///////////////////////////////////////////////////////////////////////////////////////////////////////////


	char Sex()
	{
		int ranNum=random();
		if (ranNum >= 50)
			return 'M';
		else
			return 'F';
	}

	std::string setName(std::string Bsex)
	{
		int ranNum=random();
		
		if (Bsex == "M")
		{
			if  (ranNum <= 10)
					return "Ramon";
			if  (ranNum > 10 && ranNum <= 20)
					return "Pedro";
			if  (ranNum > 20 && ranNum <= 30)
					return "Lalo";
			if  (ranNum > 30 && ranNum <= 40)
					return "Gilberto";
			if  (ranNum > 40 && ranNum <= 50)
					return "Chango";
			if  (ranNum > 50 && ranNum <= 60)
					return "Sulo";
			if  (ranNum > 60 && ranNum <= 70)
					return "Gamon";	
			if  (ranNum > 70 && ranNum <= 80)
					return "Bulo";
			if  (ranNum > 80 && ranNum <= 90)
					return "Sancho";
			if  (ranNum > 90 && ranNum <= 100)
					return "Leo";	
	}
	

	if (Bsex == "F")
	{
			if  (ranNum <= 10)
					return  "Meter";
			if  (ranNum > 10 && ranNum <= 20)
					return "Frampton";
			if  (ranNum > 20 && ranNum <= 30)
					return "Sulivan";
			if  (ranNum > 30 && ranNum <= 40)
					return "Guarra";
			if  (ranNum > 40 && ranNum <= 50)
					return "Bilasa";
			if  (ranNum > 50 && ranNum <= 60)
					return "Sefira";
			if  (ranNum > 60 && ranNum <= 70)
					return "Guarra";	
			if  (ranNum > 70 && ranNum <= 80)
					return "Zonza";
			if  (ranNum > 80 && ranNum <= 90)
					return "Sonaca";
			if  (ranNum > 90 && ranNum <= 100)
					return "Silla";	
	}
	return "";
}

	bool RMVBCheck()
	{
		int ranNum=random();
			if (ranNum == 89 || ranNum == 23 ) // check this
			{
				
				return true;
			}
			else
				return false;
	}



	class bunny
	{
	private:
		std::string Bsex;
		std::string Bcolor;
		int  Bage;
		std::string Bname;
		bool RMVB;

	public:
		bunny()
		{
			Bsex=Sex();
			Bage=0;
			RMVB=RMVBCheck();
			Bname=setName(Bsex);
			Bcolor=""; 
		
		}


		std::string chooseColor() //this function is only for first bunnies not for the ones that born
	{
		int ranNum=random();
			 
			
				if  (ranNum <= 25)
					Bcolor="White";
				if  (ranNum > 25 && ranNum <= 50)
					Bcolor="Black";
				if  (ranNum > 50 && ranNum <= 75)
					Bcolor="Brown";
				if  (ranNum > 75 && ranNum <= 100)
					Bcolor="Green";
			return "";
	}
			int birthday()  //bunnies age 1 year when called
			{ Bage+=1; return 0; }

			std::string setMomColor(std::string momColor)
			{ Bcolor=momColor; return 0; }

			int setAge(int age)
			{Bage=age;return 0;}

			std::string setSex(std::string sex)
			{Bsex=sex;return 0;}

			std::string setName2(std::string name)
			{Bname=name;return 0;}
			
			bool setRMVB(bool RMVB2)
			{RMVB=RMVB2;return 0;}
					
				
		std::string getColor()
		{return Bcolor;}

		int getAge()
		{return Bage;}

		std::string getSex()
		{return Bsex;}

		bool getRMVB()
		{return RMVB;}

		std::string getName()
		{return Bname;}
};

	

	int main()
	{
		ruleta();
		bunny b[5];
		int population=5;
		

		b[0].chooseColor();
		b[1].chooseColor();
		b[2].chooseColor();
		b[3].chooseColor();
		b[4].chooseColor();

	for(int sss=0;sss<11;sss++)
	{
		
			for (int ddd=0;ddd<=5;ddd++)  // each turn, bunnies age 1 year// change 5 to population
				{ b[ddd].birthday(); }

			for(int ddd=0;ddd<=population;ddd++)//problem wih variable population check
			{
				if(b[ddd].getAge()>10)
				{
					
					bunny *b2= new bunny[population-1];
					
					for(int iii=0;iii<ddd;iii++)
					{
						b2[iii].setAge(b[iii].getAge());
						b2[iii].setSex(b[iii].getSex());
						b2[iii].setName2(b[iii].getName());
						b2[iii].setRMVB(b[iii].getRMVB());
						b2[iii].setMomColor(b[iii].getColor());
					}
						
					for(int iii=ddd+1;iii<=population;iii++)
					{
						b2[iii-1].setAge(b[iii].getAge());
						b2[iii-1].setSex(b[iii].getSex());
						b2[iii-1].setName2(b[iii].getName());
						b2[iii-1].setRMVB(b[iii].getRMVB());
						b2[iii-1].setMomColor(b[iii].getColor());
					}
					population-=1;
				}
			}
	
	}
	return 0;
	}

I suggest making the smallest possible compilable code that demonstrates the problem you are having with a dynamically allocated class.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.