hello, I am trying to pass the array songID[numSongs] to the function playRandomSong. What am i doing wrong? The compiler is telling me "error C2660: 'playRandomSong' : function does not take 1 arguments"

#include <iostream>
#include <string>
#include <fstream>
#include <iomanip>
#include <cstdlib>
using namespace std;

const int numSongs = 15;

void playRandomSong ();


int main ()
{
	char songTYPE [numSongs];
	int songID [numSongs],
		countSongs,
		randomNum;
	bool songHasPlayed[numSongs];
	string fileName = "songData.txt";

	ifstream inFile;

	inFile.open( fileName.c_str() );  // should use constant for file name

	randomNum = rand () % numSongs;

	for (int i = 0; i < numSongs; i++)
	{
		songHasPlayed[numSongs] = false;

		if ( !songHasPlayed[randomNum] )
		{
			playRandomSong (songID);
			songHasPlayed[randomNum] = true; // change to true so it is not picked again.
		}
		else
		{
			while (songHasPlayed[randomNum] )
			
				randomNum = rand () % numSongs;
		}

	}
return 0;
}

void playRandomSong (int songID [numSongs] )
{
return;
}

line 10: That function doesn't take any parameters. It should be identical to line 48 but with a semicolon at the end.

thanks, that worked. I came up to another problem though. When i pass to that function, it is supposed to print out the values that the for/while/if setup comes out with, from the file the original array references.

okay i dont know if that makes sense but whats supposed to happen is it goes through the loops, and when the function is called it is supposed to print out a value from the array that corresponds to the index value generated by the random number sequence. how can i get it to do that?

line 30: attempting to write out-of-bounds of the array. You probably meant to index via randomNum.

okay i dont know if that makes sense but whats supposed to happen is it goes through the loops, and when the function is called it is supposed to print out a value from the array that corresponds to the index value generated by the random number sequence. how can i get it to do that?

Change the parameter of the function to a single int then pass the value you want it to play

void playRandomSong (int);

<snip>
            playRandomSong(songID[randomNum]);

<snip>
void playRandomSong (int songID);
{

}

okay thanks, but within the function how can i get it to print that out? i mean would i use a normal like cout << songID or would i need to use the inFile or would i use one of the new arrays i just set up

I have no idea because you have not poste the program requirements.

okay what i am trying to do is pass two arrays to the function playRandomSong and then print those two arrays in the "random" order. The first array is the random song ID and the second one is the "true" value gotten from the bool array songHasPlayed. This is the full program code so far....

const int NUM_SONGS = 15;

void playCurrentList (),
	 playRandomSong (int),
	 playOneSong ();



int main ()
{ 
	int menuChoice,
		songID [NUM_SONGS],
		randomNum;
	bool whatToDo = false,
		 songHasPlayed[NUM_SONGS];
	string fileName = "songData.txt";

	ifstream inFile;

	inFile.open( fileName.c_str() );  // should use constant for file name

	cout << "Welcome to the Better Music Player." << endl;

		cout << endl << setw(28) << "What would you like to do?" << endl
			 << endl << setw(36) << "1. Play Current Playlist In Order"
			 << endl << setw(30) << "2. Play Randomized Playlist"
			 << endl << setw(19) << "3. Play One Song" << endl 
			 << setw(23) << "4. Leave the Program" << endl << endl;
		cout << "Please type the number corresponding to your choice. -->";

	while ( !whatToDo )
	{			
		cin >> menuChoice;

		switch ( menuChoice )
		{
			case 1:
				playCurrentList ();
				whatToDo = true;
				break;

			case 2: randomNum = rand () % NUM_SONGS;

				for (int i = 0; i < NUM_SONGS; i++)
				{
					songHasPlayed[randomNum] = false;

					if ( !songHasPlayed[randomNum] )
					{
						playRandomSong (songID[randomNum]);
						songHasPlayed[randomNum] = true; 
                                                // change to true so it is not picked again.
					}
					else
					{
						while (songHasPlayed[randomNum] )
						randomNum = rand () % NUM_SONGS;
					}
				}
				whatToDo = true;
				break;

			case 3: 
				playOneSong ();
				whatToDo = true;
				break;

			case 4:  cout << endl << "Thank you for using the better music player." << endl;
				whatToDo = true;
				return 0;

			default: cout << endl << "Please enter a number 1 to 4." << endl;
		}
	}
return 0;
}

void playCurrentList ()
{
	char songTYPE [NUM_SONGS];
	int songID [NUM_SONGS];
	string fileName = "songData.txt";
	ifstream inFile;

	inFile.open (fileName.c_str() );

	for( int i = 0; i < 15; i++ ) // or while(inFile), declare i outside loop or
								  // declare inside and make it static
	{
		inFile >> songID [i];
		inFile >> songTYPE[i];
		cout << setw(8) << songID[i] << setw(4) << songTYPE[i] << endl;
	}
return;
}

void playRandomSong (int songID )
{
return;
}

void playOneSong ()
{
return;
}

in other words these are my guidelines for the random section....

Set up two arrays, also parallel to your first two arrays. The first array contains indexes into the song IDs array, and will store the randomized playlist as these indexes. The second array will contain false if the song at that index has not already been chosen to play, and it will contain true if it has already been chosen. You must not allow any duplicates in your randomized playlist. For example, let's say that we have randomized the entire playlist and song 1 is to play last, song 2 first, and song 3 in the middle. We would have, in our two arrays: How do you generate the indexes stored in the first array shown here? Call rand( ), as in rand( ) % NUMBER_OF_SONGS . This will generate a valid index into the song IDs array. Data Structures This project is meant to familiarize you thoroughly with the use of one-dimensional arrays in C++ and with utilizing an enum type. You are required to use two one-dimensional arrays to store the song IDs and the corresponding song types. In addition you must use two one-dimensional arrays to store information to play songs randomly: first, an array of indexes into the song IDs array telling you what order to play the songs in, and second, an array of true/false values telling you if a song has already been chosen to play or not. You must use the typedef construct to set up your enum type for the song types
1
2
0
true
true
true

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.