Baby Name Generator

Pages: 12
Okay so I am super brand new to coding and im trying to create a baby name generator I have this so far, but im super stuck on what to do next. I anybody can help a newbie out I would appreciate it. Thanks. It has to be made with a 2 dimensional array fyi.

#include <iostream>

using namespace std;


int main(){
float babyNames [2][24];
int BOY_JAMES = 0;
int BOY_CALEB = 1;
int BOY_TROY = 2;
int BOY_MARCUS = 3;
int BOY_AYRTON = 4;
int BOY_ERIC = 5;
int BOY_BRANDON = 6;
int BOY_MATTHEW = 7;
int BOY_TAYLOR = 8;
int BOY_LIAM = 9;
int BOY_CODY = 10;
int BOY_DEVIN = 11;
int BOY_CHRIS = 12;
int GIRL_KELSEY = 0;
int GIRL_BRIANNA = 1;
int GIRL_HANNAH = 2;
int GIRL_SARAH = 3;
int GIRL_JESSICA = 4;
int GIRL_MELIANA = 5;
int GIRL_NANCY = 6;
int GIRL_MARLENE = 7;
int GIRL_KIM = 8;
int GIRL_COLEEN = 9;
int GIRL_ADRIANNA = 10;
int GIRL_ZOEY = 11;
int GIRL_MAKENNA = 12;
What is your program all about?
its asks the user to choose a gender boy or girl and it will choose a random name and give it to the user then it restates the question boy or girl so the user can do it over if they want to.
You could do it that way, what I mean is you could hard code in the names, but it's going to be a devil of a time to change a 3000 line program.

I suggest put the names in a file boynames.txt girlnames.txt you might even use multigender names that could be girl or boy.

only read in the file that you need unless they want all names.

Later you may want to make your array more complex and you won't have to change as much code.
I just need it super basic
Have you learned std::ifstream?
Have you learned array?
Have you learned std::vector?
Last edited on
yes i have
Have you learned std::ifstream?
Have you learned array?
Have you learned std::vector?

> Yes i have
That makes the task too simple. What is your next question?

Last edited on
i have only learned the first two not vector my question is what is my next step of the program after setting up the 2 dimensional array im stuck
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
float babyNames [2][24];
int BOY_JAMES = 0;
int BOY_CALEB = 1;
int BOY_TROY = 2;
int BOY_MARCUS = 3;
int BOY_AYRTON = 4;
int BOY_ERIC = 5;
int BOY_BRANDON = 6;
int BOY_MATTHEW = 7;
int BOY_TAYLOR = 8;
int BOY_LIAM = 9;
int BOY_CODY = 10;
int BOY_DEVIN = 11;
int BOY_CHRIS = 12;
int GIRL_KELSEY = 0;
int GIRL_BRIANNA = 1;
int GIRL_HANNAH = 2;
int GIRL_SARAH = 3;
int GIRL_JESSICA = 4;
int GIRL_MELIANA = 5;
int GIRL_NANCY = 6;
int GIRL_MARLENE = 7;
int GIRL_KIM = 8;
int GIRL_COLEEN = 9;
int GIRL_ADRIANNA = 10;
int GIRL_ZOEY = 11; 
int GIRL_MAKENNA = 12;

2D array of floats but have ints?
I would recommend using strings, like so:
1
2
3
    const std::string boy_names[no_of_names]{ "James", "Caleb", "Troy" },
                        girl_names[no_of_names]{ "Kelsey", "Brianna", "Hannah" };
    const std::string names[][no_of_names]{ boy_names, girl_names };


what is my next step of the program

Do you know how to generate a random number?
No thats what im stuck on
nightskyxXx wrote:
No thats what im stuck on

This would be the easiest way.
1
2
srand( time( nullptr ) );
int rand_num{ rand( ) % no_of_names };

http://www.cplusplus.com/reference/cstdlib/rand/
Last edited on
Okay for the names i have to have 12 and then what would to look like then with the 12?
Okay so this is what i have
#include <iostream>

using namespace std;

int main (){

const std::string boy_names [no_of_names]{all boys names here},
girl_names [no_of_names]{all girl names here};
const std::string names [][no_of_names]{boy_names, girl_names};
srand (time (nullptr) ); int rand_num { rand ( ) % no_of_names}; whats the next step?
The next step is the easy step. You should be able to solve it yourself.
You forgot to #include some headers.
Last edited on
Do i add them on the const std? And then the last ones an end } huh?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <iostream>
// include whatever headers are needed
using namespace std;    // when doing this, you don't need to type std::

int main( )
{
    const std::string boy_names [no_of_names]{ /*all boys names here*/ },
                    girl_names [no_of_names]{ /*all girl names here*/ };
    const std::string names [][no_of_names]{ boy_names, girl_names }; 

    srand ( time (nullptr) ); 
    int rand_num { rand ( ) % no_of_names };

    // Ask user for gender
    // Compare gender and choose from the 2D names array using rand_num
    // Output name
    // ???
    // Profit
}
For when they put an input after i ask the question how should it be worded just like genderInput?
Also how do i set up to make it use the 2d name array im confused on that part
@nightskyxXx

Here's using those baby names in the 2D array. You choose if you need a girls name or a boy, and one of them will be displayed.

You'll need to use srand() first, so a different random number is selected.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <iostream>
#include <string>

using namespace std;


int main()
{
	string babyNames[2][24] = {
		{ "JAMES", "CALEB", "TROY", "MARCUS", "AYRTON", "ERIC",
 "BRANDON", "MATTHEW", "TAYLOR", "LIAM", "CODY", "DEVIN", "CHRIS" },// Room for 24 boys name
		{ "KELSEY", "BRIANNA", "HANNAH", "SARAH", "JESSICA",
 "MELIANA", "NANCY", "MARLENE", "KIM", "COLEEN", "ADRIANNA", "ZOEY", "MAKENNA" }// Room for 24 girls names
	};
	char sex;
	int chosen;
	cout << "Do you wish a Girl's name, or one for a Boy ?" << endl;
	cout << "\tEnter a 'G' or a 'B'" << endl;
	do
	{
		cin >> sex;
		sex = toupper(sex);
	} while (sex != 'G' && sex != 'B');

	if (sex == 'B')
		chosen = 0;
	else
		chosen = 1;
	int pick = rand() % 13;//Change to number of names..
	cout << "The random name is " << babyNames[chosen][pick] << endl;
}
Last edited on
Pages: 12