Random Name Generator (prefix + suffix)

The Partridge Family were neither partridges nor a family. Discuss.
Post Reply
Natox
Posts: 51
Joined: January 10th, 2012, 2:51 pm
Location: the Netherlands
Contact:

Random Name Generator (prefix + suffix)

Post by Natox » February 1st, 2012, 10:29 pm

Hey chili, I made a random name generator with prefix and suffix options!
What do you think? ( made it from the head to figure out arrays! )

Code: Select all

/*	DEVELOPER: John van den Elzen
	PROGRAM: Random Name Generator
	PURPOSE: Exercise C++ programming */

#include <iostream>
#include <ctime>
#include <string>

using namespace std;

int main(){

	srand(time(NULL));

	string prefixArray[7] = {"Almighty","Enormous","Godly","Hunters","Insane","Kings","Poisonous"};
	string suffixArray[7] = {"Walkingstick","Greatsword","Axe","Crossbow","Katana","Fistblade","Dagger"};


	for(int i = 0 ; i < 10 ; i++){

		cout << prefixArray[(rand() % 7)] << " " << suffixArray[(rand() % 7)] << endl;

	}



	system("PAUSE");
	return 0;
}
Check my forum for explanation: http://www.gamer-bay.com/forums/viewtopic.php?f=5&t=9
My Weblog: http://www.gamer-bay.com/
Keep track of my learning progress on the C++ programming language.

User avatar
chili
Site Admin
Posts: 3948
Joined: December 31st, 2011, 4:53 pm
Location: Japan
Contact:

Re: Random Name Generator (prefix + suffix)

Post by chili » February 2nd, 2012, 4:08 am

Seems like you've got the knack of generating random numbers down now. :)

You've got a good start on arrays there too. If you want, I could give you another challenge to hone your array skills with. :idea:
Chili

Natox
Posts: 51
Joined: January 10th, 2012, 2:51 pm
Location: the Netherlands
Contact:

Re: Random Name Generator (prefix + suffix)

Post by Natox » February 2nd, 2012, 8:57 am

Sounds good to me, bring it on! But make it fun :-)
My Weblog: http://www.gamer-bay.com/
Keep track of my learning progress on the C++ programming language.

User avatar
chili
Site Admin
Posts: 3948
Joined: December 31st, 2011, 4:53 pm
Location: Japan
Contact:

Re: Random Name Generator (prefix + suffix)

Post by chili » February 2nd, 2012, 2:06 pm

Natox wrote:make it fun
Bro, this is C++ we're talkin' about here! How could it be anything but? :P

Okay, so here's the mission. It's actually something that I plan on doing in a later lesson after I introduce arrays (shortly after we make the Tic Tac Toe game). You're gonna need the poo solution so I hope you didn't delete that folder.

1) Make it so that the poo data are stored in arrays instead of in individual variables.

2) Make it so that the position of poo is randomly initialized at the start of the game.

3) Make it so that by changing one value, you can set the number of poos. (Hint: you can put #define NUMBERPOO 69 at the top of your game.h file and then use NUMBERPOO throughout your game.h and game.cpp whereever you need to represent the number of poops.)

4) Make the poo move around (for example, bouncing off the walls).

5) Make it so that the goal is not to collect the poo, but to avoid it.

I think this will be a very good excercise in using arrays and loops together for great justice. 8-)
Chili

tonythedemon
Posts: 7
Joined: January 28th, 2012, 10:12 pm
Contact:

Re: Random Name Generator (prefix + suffix)

Post by tonythedemon » February 2nd, 2012, 8:54 pm

looks a bit confusing are you going to teach use how to do this ?

Natox
Posts: 51
Joined: January 10th, 2012, 2:51 pm
Location: the Netherlands
Contact:

Re: Random Name Generator (prefix + suffix)

Post by Natox » February 3rd, 2012, 3:15 am

chili wrote:
Natox wrote:make it fun
Bro, this is C++ we're talkin' about here! How could it be anything but? :P

Okay, so here's the mission. It's actually something that I plan on doing in a later lesson after I introduce arrays (shortly after we make the Tic Tac Toe game). You're gonna need the poo solution so I hope you didn't delete that folder.

1) Make it so that the poo data are stored in arrays instead of in individual variables.

2) Make it so that the position of poo is randomly initialized at the start of the game.

3) Make it so that by changing one value, you can set the number of poos. (Hint: you can put #define NUMBERPOO 69 at the top of your game.h file and then use NUMBERPOO throughout your game.h and game.cpp whereever you need to represent the number of poops.)

4) Make the poo move around (for example, bouncing off the walls).

5) Make it so that the goal is not to collect the poo, but to avoid it.

I think this will be a very good excercise in using arrays and loops together for great justice. 8-)
I'll start working on this, next sunday or monday, since I'm kinda busy with work atm.
I will keep you informed on my progress!
My Weblog: http://www.gamer-bay.com/
Keep track of my learning progress on the C++ programming language.

XxSpeedDemonxX
Posts: 4
Joined: February 23rd, 2012, 1:26 am

Re: Random Name Generator (prefix + suffix)

Post by XxSpeedDemonxX » February 23rd, 2012, 2:52 am

Strange, when you try to make it cout<< into a prompt then you get some strange number and letter sequence

Code: Select all

/*   DEVELOPER: John van den Elzen
   PROGRAM: Random Name Generator
   PURPOSE: Exercise C++ programming */
#include <iostream>
#include <ctime>
#include <string>

using namespace std;

int main(){

   srand(time(NULL));
   string prefixArray[7] = {"Almighty","Enormous","Godly","Hunter's","Insane","King's","Poisonous"};
   string suffixArray[7] = {"Walkingstick","Greatsword","Axe","Crossbow","Katana","Fistblade","Dagger"};
   cout<<prefixArray<<suffixArray<<"\n";
   cin.get();}
(XxSpeedDemonxX)-Tristan Gibson

"We don't see those who want to change the world as crazy, but genius. Anyone who is crazy enough to believe they can change the world most likely will."

User avatar
chili
Site Admin
Posts: 3948
Joined: December 31st, 2011, 4:53 pm
Location: Japan
Contact:

Re: Random Name Generator (prefix + suffix)

Post by chili » February 23rd, 2012, 3:26 am

Code: Select all

cout<<prefixArray<<suffixArray<<"\n";
That's because you're using the arrays without their indices (e.g. [0], [3], etc.).

Those letters and numbers are probably the addresses of the first location in the array.
Chili

Post Reply