Archived

This topic is now archived and is closed to further replies.

Random Quotes...

This topic is 6009 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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!

Share this post


Link to post
Share on other sites
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!

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites