Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdlib>
- #include <ctime>
- using namespace std;
- void shuffle( int [ 10 ] );
- void playorder( const int [10], const char *[]);
- int main() {
- int songorder[10] = {0};
- const char *mymp3list[ 10 ] =
- {"Happy","Dark Horse","Talk Dirty","All Of Me","Drunk In Love",
- "Pompeii","Team","Say Something","Counting Stars","Timber"};
- cout << "Original Song Order:" << endl;
- for (int i= 1 ; i <= 10 ; ++i)
- cout << i << ". " << mymp3list[i-1] << endl;
- cout << "Shuffled Order:" << endl;
- srand( time( 0 ));
- shuffle( songorder );
- for (int i = 0; i < 10 ; ++i )
- cout << i+1 << "->" << songorder[i] << " " ;
- cout << endl<< endl;
- playorder( songorder, mymp3list );
- return 0;
- }
- void shuffle( int order[ 10 ] ){
- // places the numbers from 1 to 10 in random order in the array order
- int position;
- int i;
- for (i= 1; i <= 10; i++ ) {
- do {
- position = rand() % 10;
- } while( order[position]!= 0 );
- order[position] = i;
- }
- }
- void playorder( const int order[ 10 ], const char *songlist[] ) {
- // prints out the songs in order given by order
- for ( int song = 1; song <= 10; song++ )
- for ( int position = 0; position < 10; position++ )
- if ( order[position] == song )
- cout << song << ". " << songlist[ position ] << "\n";
- cout<< endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment