MoonRiver OldPeoplesSongs AndyWilliams 2:30 EasyListening
MoonRiver1 OldPeoplesSongs1 AndyWilliams1 2:31 EasyListening1
MoonRiver2 OldPeoplesSongs2 AndyWilliams2 2:32 EasyListening2
MoonRiver3 OldPeoplesSongs3 AndyWilliams3 2:33 EasyListening3
MoonRiver4 OldPeoplesSongs4 AndyWilliams4 2:34 EasyListening4
MoonRiver5 OldPeoplesSongs5 AndyWilliams5 2:35 EasyListening5
MoonRiver6 OldPeoplesSongs6 AndyWilliams6 2:36 EasyListening6
MoonRiver7 OldPeoplesSongs7 AndyWilliams7 2:37 EasyListening7
MoonRiver8 OldPeoplesSongs8 AndyWilliams 2:38 EasyListening8
So if you type in AndyWilliams1 it will display all the information pertaining to that line above.
**The problem i am having is that say if i have an artist that has written more than one song like for example the first and last one of the input: "AndyWilliams" it will only display the first one. It is like the program skips over the second time it see the same artist...
**If anyone can go through and figure this out that would be great.
**If you want to program to run this on your comp you can just create file called songs.dat and copy and paste the info above.
Thanks any help would be greatly appreciated.
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
//Struct used for array songs[200]
//and labels each piece of info in file
struct SongType
{
string title;
string album;
string artist;
string time;
string genre;
};
int main ()
{
int i = 0; //first piece of data in the array used for counter
int songCount; //Number of songs in the file
string more = "Yes"; //allows first entrance into loop
string username; //Artist's name entered by user
//Declare and open files
ifstream inData;
inData.open("songs.dat");
SongType songs[200]; //declaration of an array
//loop that reads each piece of information in an array
while(!inData.eof())
{
inData >> songs[i].title >> songs[i].album >> songs[i].artist
>> songs[i].time >> songs[i].genre;
i++; //counter
}
songCount = i; //the number of songs in the file
//Loop that reiterates if the user wants to find out more information about other artists
while ((more == "Yes") || (more == "yes"))
{
//displays a message asking for the artist name and then they enter it
cout << "Please enter the artist of your choice:";
cin >> username;
cout << endl;
//Loop that tries to match up the artist name the user entered
//to one in the file
for (i=0; i<songCount; i++)
{ //If the user entered an artist name corresponding to
//one in the file enters loop and displays message
if (username==songs[i].artist)
//Displays a message corresponding to the users artist entry
cout << username << " wrote the song " << songs[i].title
<< " which is on the album " << songs[i].album
<< '.' << endl << "The length of the song is "
<< songs[i].time << ", and the genre of the music is "
<< songs[i].genre << '.' << endl << endl;
else i++; //used for if statement below
}
if (i == songCount) //Checks if the user entered an invalid
//artist name and displays a messege if so
{
cout << "Check the spelling of the artist, or we do not "
<< endl << "have any information on that artist."
<< endl << endl; //displays a message and ends
//lines for neatness
}
cout << "Would you like to find out more about another artist?"
<< "(Enter Yes or No): "; //Asks user question
cin >> more; //user enters yes or no to continue
cout << endl; //ends line for neatness
}
inData.close(); //close file songs.dat
return 0;
}

New Topic/Question
Reply



MultiQuote



|