Need help with this code ::: the answer i am getting at the end does not match the expected answer ....
At the start there are 1 male and 2 females kitten 2 month old.
After every 4 months each female give birth to 6 kittens , 2
males and 4 females.Females at the age of 6 months start giving birth.Each kitten dies after 2 years both male & female
::: at the end of year one there should be 58 females and 29 males but my code is giving me 50 females and 9 males...can anyone please guide me in the right direction or tell me what am i doing wrong.:::
#include <iostream>
usingnamespace std;
int main ()
{
float sum_male=1,sum_female=2;
float y,next_male,next_female,n;
cout<<" Enter the number of years"<<endl;
cin>>n;
y= (n*12+2)/4;
for ( int i=1;i<=y;i++)
{
next_male=(sum_male*2);
next_female=(sum_female*4);
sum_male=sum_male+next_male;
sum_female=sum_female+next_female;
}
cout<<" Total male after years "<<sum_male<<endl;
cout<<" Total female after years "<<sum_female<<endl;
return 0;
}
Well, I am not sure why you aren't doing this with classes. I don't think a simple loop like that will help you with doing all the calculations (such as females only giving birth after 6 months old).
next_male=(sum_male*2);
^ This line is definitely wrong. The number of males born are dependent on the number of females, not males (well, as long as there is at least 1 male).
thnks for your reply ....because i have an inadequate substitute as a prof...he spent 3 hours staring at this in class..said nobdoy told him we were going to do this n thn declared it a home task -__-
so the whole logic is wrong ?.... maybe we have to do it with fibonacci rabbit sequence...but i am not sure how the month will be used in this sequence .....or where to multiply the females (maybe nex*4 ?)
# include <iostream>
usingnamespace std;
int main ()
{
int fact=1,num,a=0,b=1,next=0,i,sum=0;
float month;
cout<< " enter the value : "<<endl;
cin>>num;
cout<<" Enter the number of years"<<endl;
cin>>n;
month= (n*12)/4;
cout<<a<<endl<<b;
for (i=1;i<=num-2;i++ )
{ next= a+b;
cout<<next<<endl;
a=b;
b=next;
}
return 0;
}
hey thnx for the reply .... no i am not familiar with structs or classes or vector....i am just a beginner
i tried following the direction but the code keeps giving me garbage value =S ...where am i messing it up