In my program I have set up two parallel arrays from a given file. The file looks something like this and has 15 lines:
1233 C
3222 R
and so forth.
In my program the user has to pick a number , 1-15, and that line of the array must be outputted. I am able to print out the entire array, but can not get it to just retrieve the user specified line. Any pointers?
My code is as follows:
// arrays
typedefint sizeOfId[15];
typedefchar sizeOfType[15];
sizeOfId songId;
sizeOfType typeOfSong;
// variable that stores the users choice
int songChoice;
cout << endl << "Please enter the number of the song that you would like to play:";
cin >> songChoice
//bad data checking because the choice has to be between 1 and 15
while (songChoice >15 || songChoice < 1)
{
cout << "You have not entered a valid song choice- please try again:";
cin >> songChoice
}
int songNum =0;
while (songChoice <= 15 && inFile >> songId[songChoice] >> typeOfSong[songChoice])
{
songChoice--;
cout << songId[songChoice] << typeOfSong[songChoice] << endl;
}