Reputation: 45
I'm trying to build a CD collection program in C# that can
I'm stuck on the 3rd bit, adding details to each album, so far i have this, i figure when i get this right, the rest of the details will be easy to add
public bool AddSong(string songName)
{
for (int i = 0; i < MAX_MUSIC; i++)
{
string c = albumName; // This compares the album name given by user
string e = myMusic[i].getAlName; // to the album name in the myMusic array
int d = c.CompareTo(e); //
if (d == 0)
{
int index = -1;
for (int j = 0; j < MAX_SONG; j++)
{
if (Songs[i] == null)
{
index = i;
break;
}
}
if (index != -1)
{
Songs[index] = songName;
++totalSongs;
return true;
}
}
}
return false;
}
any help to give me direction would be much appreciated.
EDIT: This is homework, I'm an external student and my lecturer as nice as he is, doesn't speak english very well, I don't expect freebies. Just direction on approach and maybe an odd hint ;)
EDIT2: My code is very large so i dont think it is appropriated to post such large amounts of code, i can though provide a link to the classes
Upvotes: 0
Views: 260
Reputation: 17964
for (int j = 0; j < MAX_SONG; j++) { if (Songs[i] == null) { index = i; break; } }
You're looping through j but you're not using j in your for loop. So you're really doing the same thing MAX_SONG times.
Upvotes: 1
Reputation: 67296
if (index != -1)
{
Songs[index] = songName;
++totalSongs;
return true;
}
This is the section you need to focus on now.
Ask yourself:
Song
class (initialize)?Song
class?Song
to the correct position in the array?Upvotes: 1