Baby Name Generator

Pages: 12
Whitenite1 you talking about placing the srand () in the global scope?
@nightskyxXx

No. You can place srand((unsigned) time(0)); on a line right after main().
Don't forget to add #include <ctime> with your other includes, as this srand uses the current time to seed the random number generator.
whitenite1 im having an warning with the girl names it says that the expression result unused why is that?
Actually i fixed that but now im getting error stating all the COUTs and IF and DO and WHILE and ELSE are unknown and expected unqualified-id
@nightskyxXx

The only thing I can figure, is that you forgot a semicolon at the end of a command. Why not post your code, and it might be easier to see the reason.
#include <iostream>
#include <string>
#include <ctime>

using namespace std;

int main (){
char sex;
int chosen;
srand (unsigned) time (0));
string babyNames [2][24] = { "JAMES", "CALEB", "TROY", "MARCUS", "AYRTON", "ERIC", "BRANDON", "MATTHEW", "TAYLOR", "LIAM", "CODY", "DEVIN", "CHRIS"},
{ "KELSEY", "BRIANNA", "HANNAH", "SARAH", "JESSICA", "MELIANA", "NANCY", "MARLENE", "KIM", "COLEEN", "ADRIANNA", "ZOEY", "MAKENNA"}
};
cout << "Do you wish a Girl's name, or a Boys? << 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 () % 24;
cout << "The random name is" <<
babyName[chosen][pick] << endl;
}

This is what i have
@nightskyxXx

Well, the problem is because you have only one left parenthesis at the start of babyNames. There are two sets of names, so you need two parenthesis'. ( Look at my code I showed you. ) Plus, you are getting a random number up to 24, but only have 13 boys and 13 girls, names.

One last problem, you forgot the closing quotes on these two lines..
1
2
cout << "Do you wish a Girl's name, or a Boys? << endl; // No quotes found after Boys? 
cout << "/tEnter a 'G' or a 'B' << endl; // No quotes found after B'  


You may also want to put a space after is, in name is" otherwise the name printed will be connected to it.
So then for the numbers it should be 13 where i have 24 right?
It works thank you so much Whitenite1 i appreciate your help is it okay if i contact you if i need anymore help in the future?
Last edited on
@nightskyxXx

Yes you can. I would be glad to offer assistance.
And in answer to
So then for the numbers it should be 13 where i have 24 right?

Correct. Of course, change the 13 later to equal any more names you add. If you want more than 24 girls names and boys names, change it also, accordingly, for the array size. You'll have to recompile, of course.
Topic archived. No new replies allowed.
Pages: 12