Page 1 of 1

Random Name Generator (prefix + suffix)

Posted: February 1st, 2012, 10:29 pm
by Natox
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

Re: Random Name Generator (prefix + suffix)

Posted: February 2nd, 2012, 4:08 am
by chili
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:

Re: Random Name Generator (prefix + suffix)

Posted: February 2nd, 2012, 8:57 am
by Natox
Sounds good to me, bring it on! But make it fun :-)

Re: Random Name Generator (prefix + suffix)

Posted: February 2nd, 2012, 2:06 pm
by chili
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-)

Re: Random Name Generator (prefix + suffix)

Posted: February 2nd, 2012, 8:54 pm
by tonythedemon
looks a bit confusing are you going to teach use how to do this ?

Re: Random Name Generator (prefix + suffix)

Posted: February 3rd, 2012, 3:15 am
by Natox
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!

Re: Random Name Generator (prefix + suffix)

Posted: February 23rd, 2012, 2:52 am
by XxSpeedDemonxX
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();}

Re: Random Name Generator (prefix + suffix)

Posted: February 23rd, 2012, 3:26 am
by chili

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.