When I call out add_record in main the output looks like this Title? Artist? Why is it not waiting for Title and skiping to Artist? It's like it's reads in title aoutomatically. Do I need to call out a constructor and initialize my strings.
class CD_Database {
public:
struct CD_TYPE {
string title;
string artist;
string albumsingle;
float price;
int tracks;
};
typedef struct CD_TYPE CD_T;
void Add_Record();
}; /*end class CD_Databae*/
/* This is input.h */
string read_string(string disp_string)
{
string answer;
cout << disp_string;
getline (cin, answer);
return (answer);
}
void CD_Database::Add_Record()
{
CD_T one_cd;
one_cd.title = read_string("Title? ");
one_cd.artist = read_string("Artist? ");
one_cd.tracks = read_int("Number of tracks? ");
if (yesno("Is it an Album y or n?"))
one_cd.albumsingle = "Album";
else
one_cd.albumsingle = "Single";
I flushed out cin using cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n') and it works now. Was this bad code that I wrote or is this just bugy?