I am new to C++ and I am writing a program that will simulate a bunny colony. The program will automatically add them, and give them names, gender, age, etc. I am slowly adding in features to the bunnies and I am starting with the names first. When I compile and run the program I get this output, any advice on how I can resolve this issue?
The output:
Name:
Sex:
Color:
Age: 0
Name:
Sex:
Color:
Age: 0
Name:
Sex:
Color:
Age: 0
Name:
Sex:
Color:
Age: 0
Name:
Sex:
Color:
Age: 0
What I have tried:
#include <iostream>
#include <string>
#include <ctime>
#include <vector>
#include <cstdlib>
using namespace std;
char getSex();
string getColor();
int getAge();
string getName();
void printBunny();
int randomGeneration(int x);
static std::string possibleNames[] ={
"Jen",
"Alex",
"Janice",
"Tom",
"Bob",
"Cassie",
"Louis",
"Frank",
"Bugs",
"Daffy",
"Mickey",
"Minnie",
"Pluto",
"Venus",
"Topanga",
"Corey",
"Francis",
"London",
};
static std::string possibleColors[] ={
"White",
"Brown",
"Black",
"Spotted"
};
struct Bunny
{
char sex;
string color;
int age;
string name;
bool radioactive_mutant_vampire_bunny;
BunnyData()
{
setSex();
setColor();
setAge();
setName();
}
int randomGeneration(int x){
return rand() % x;
}
void setSex()
{
int randomNumber = 1 + rand() % 2;
( randomNumber == 1 ) ? sex = 'm' : sex = 'f';
}
char getSex()
{
return sex;
}
void setColor()
{
}
string getColor()
{
return color;
}
void setAge()
{
age = 0;
}
int getAge()
{
return age;
}
void setName()
{
int i = randomGeneration(18);
name = possibleNames[i];
}
string getName()
{
return name;
}
void printBunny()
{
cout << "Name: " << getName() << endl;
cout << "Sex: " << getSex() << endl;
cout << "Color: " << getColor() << endl;
cout << "Age: " << getAge() << endl;
}
};
int main()
{
vector< Bunny > colony;
cout << "Welcome to Bunny Graduation!" << endl << endl;
for( int i = 0; i < 5; ++i )
{
colony.push_back( Bunny() );
}
for( int i = 0; i < 5; ++i )
{
colony[ i ].printBunny();
cout << endl;
}
return 0;
}