Welcome to Dream.In.Code
Become a C++ Expert!

Join 149,710 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 2,253 people online right now. Registration is fast and FREE... Join Now!




Random Name Generator

 
Reply to this topicStart new topic

Random Name Generator

Squirrel
6 Feb, 2007 - 12:16 PM
Post #1

D.I.C Head
**

Joined: 6 Feb, 2007
Posts: 61


My Contributions
I am trying to get familiar with higher functions in our CSE100 class so I am attempting a sample problem of my own. I was wondering if maybe you could help me out. I am trying to create a random name generator (first and last). The first name and last names are in a variable list (firstname1, firstname2, etc) and I initialized every one equal to a different name (firstname1 = “John “wink2.gif etc. I was wondering how I would get it to randomly select one of these strings. This is kinda what I want the program to do in the end:



RANDOM NAME GENERATOR



Press enter to generate a name… <user presses enter>



Random name = John Doe



Press enter to generate a name… <user presses enter>



Random name = Jane Doe



And so on and so forth in an infinite loop. I know I would probably need it to randomly generate a number between 1 and N, then select the corresponding string value. It would then need to do that twice to get the last name selected as well.

I have all the variables working, etc... I just dont know how to get the randomizer to work


User is offlineProfile CardPM
+Quote Post

max302
RE: Random Name Generator
6 Feb, 2007 - 01:42 PM
Post #2

Proud supporter of the lulz
Group Icon

Joined: 5 Mar, 2006
Posts: 1,281


Dream Kudos: 200
My Contributions
The form you have mentioned, firstname1 and lastname one, will just not work. I was thinking about a bitchingly big array. In this form:
CODE

string firstname[400];

firstname[1] = "Joe";
firstname[2] = "Louis";
firstname[3] = "Bob";
......


and so on and so forth. The next thing that you need to consider is getting a random number. I'm pretty sure that you can find lots of info on randomization on the internet.
User is offlineProfile CardPM
+Quote Post

Squirrel
RE: Random Name Generator
6 Feb, 2007 - 02:20 PM
Post #3

D.I.C Head
**

Joined: 6 Feb, 2007
Posts: 61


My Contributions
QUOTE(max302 @ 6 Feb, 2007 - 02:42 PM) *

The form you have mentioned, firstname1 and lastname one, will just not work. I was thinking about a bitchingly big array. In this form:
CODE

string firstname[400];

firstname[1] = "Joe";
firstname[2] = "Louis";
firstname[3] = "Bob";
......


and so on and so forth. The next thing that you need to consider is getting a random number. I'm pretty sure that you can find lots of info on randomization on the internet.


Would you declare the variables like normal, such as string firstname1, firstname2, firstname3, etc?

EDIT: Im assuming the top line is declaration. string firstname[400] assigns 400 variables already?

This post has been edited by Squirrel: 6 Feb, 2007 - 02:45 PM
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 1/8/09 04:30AM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month