I'm making a program that reads in data from a file into 2 different arrays (one is an int array and another is a char array). And they are parallel. These are songs and song types (hip hop, jazz...etc). I want to print the songs as a playlist then I want to be able to randomize the playlist. To do this I want to make two more parallel arrays, one that randomizes the song name index and the other that consists of true and false values so that a song isn't played more than once that are also parallel to the other first two. But I DON'T want to print the same song more than once. How can I accomplish this (not repeating a song)?
cnet1989
Recommended Answers
Jump to PostSo it sounds like this is data that gets paired together. So you have something like this:
1 R 2 B 3 F 4 W
where 1, 2, 3, 4 are song numbers. And R, B, F, W are letters representing song type? And you want to …
Jump to PostJust read your post a little more closely (and I see you just posted again too). I think I get it a little bit better now, but I'm not sure. You have four songs:
1 2 3 4
You want to play these four songs in random …
Jump to PostWell, you're working with arrays of 4 elements, so you are really interested in randomizing the array indexes that go along with those arrays. So you want to create random numbers from 0 to 3 and have them occur exactly one.
You are using:
rand () …
Jump to Postfor (int i = 0; i < numsongs; i++) { if ( !truefalsearray[randomNumber] ) { <pass to function that prints song> (songArray[randomNumber] ); truefalsearray[randomNumber] = true; // change to true so it is not picked again. randomNumber =rand () % numsongs } // if else { while …
All 13 Replies
VernonDozier 2,218
Posting Expert Featured Poster
cnet1989
VernonDozier 2,218
Posting Expert Featured Poster
cnet1989
VernonDozier 2,218
Posting Expert Featured Poster
cnet1989
VernonDozier 2,218
Posting Expert Featured Poster
cnet1989
VernonDozier 2,218
Posting Expert Featured Poster
hammerhead 19
Posting Whiz in Training
cnet1989
VernonDozier 2,218
Posting Expert Featured Poster
cnet1989
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.