array

need little help here
i have array with some description of items in it.
in function countAudioCDs() i need to look for item "Audio CD" and increment it for output.
it alwasy gives me 3, even if i had 10 AudioCD in array
im not sure what im doing wrong

this is just part of program, everything else works

char productDesc[NUM_ROWS][DESC_SIZE] =
{ "Book", "Audio CD", "DVD",
"Book", "Audio CD", "DVD",
"Book", "Book", "Audio CD"
};

void countAudioCDs(char audio[][DESC_SIZE], const int NUM_ROWS)
{
cout << endl;
int description;
if (strcmp(audio[description], "AudioCD") == 0)
description ++;

cout << "The number of \"Audio CD\" titles is: " << description << endl;
}
Last edited on
Your "description" doesn't seem to ever be initialized and you aren't in a loop of any kind so I don't see how it counts anything at all.
i initalized description = 0 which gives me 0 in the output
and isn't it if(strcmp(string1, string2) == 0) a loop?
im not sure what kind of loop can i put in there.
problem solved
i had to put if(strcmp(),==0) in for loop
Topic archived. No new replies allowed.