Random Quotes...

Started by
3 comments, last by flyguy 22 years, 10 months ago
Hi... How would I write the randomizing part of a random quotes program? Say I have 50 quotes or 100 quotes that I want to have in a program. I then generate 50 or 100 random numbers respectively, in the range of 1-50 or 1-100. How would I associate those random numbers with the quotes? Basically I need the randomizing code for a random quotes program in DOS. C++. Thank you!
"And I invented the internet!" - Al Gore
Advertisement
int GetRandomQuote(int numofquotes)

{

randomize();

int quotenum = rand() % numofquotes;

return quotenum;

}

I think that should do the trick.
quote:Original post by Crazy_Vasey
int GetRandomQuote(int numofquotes)

{

randomize();

int quotenum = rand() % numofquotes;

return quotenum;

}

I think that should do the trick.


Basically what I''m trying to do is:

The user inputs a number of names. First they say how many names. I use a switch (numnames) statement to tell the program what to do depending on how many names there are. What I need it to do is take the char name1[60] char name2[60] char name3[60] char name4[60] ect. and put these in a random order, then print out the names. The number of names they enter has to be even otherwise it doesn''t work. This is sort of like a random team generator for games and stuff.

Help!

"And I invented the internet!" - Al Gore
I guess you are already using a 2D array? ie Teams[NUMOFTEAMS][MAXNAMESIZE]

code follows

  bool PutInRandomOrder(){int temp;bool Check;Randomize();bool TeamCheck[NUMOFTEAMS];int TeamNumber[NUMOFTEAMS];for (int i = 0 ; i < NUMOFTEAMS; i++){while(Check != true){temp = rand() % NUMOFTEAMS;if (TeamCheck[temp] != true) { TeamNumber[i] = temp; break; }}}for (int j = 0; j < NUMOFTEAMS; j++)printf("%s",TeamName[i]);return true;}  


Okay that assumes Teamnames is in a 2D array and is called TeamName but it should give you the general idea.






Edited by - Crazy_Vasey on June 29, 2001 3:09:16 PM
BTW my code isnt normally that ugly but coding in a crappy HTML input form isnt much fun.

This topic is closed to new replies.

Advertisement