Hi. I have this assignment and have absolutely hit a wall here. I will give the assignment details, then say what the issue is:

Consider a collection of songs in an MP3 library where each song is characterized by artistName, songTitle, album, playTime (in seconds), musicCategory, and albumProducer – hence, you will need to use a struct data type. The musicCategory is represented by an enumeration type called SongCategory. The MP-3 library can hold a maximum of 200 songs at a time. The collection of songs is stored in a text file, which you will need to create with songs of your choice. You are free to select any format by which the songs are stored in the text file.

Write a program that reads the songs data from the text file, and stores it in an array of the struct data type, each of which represents a song in the library
- PrintAllRecords: Outputs to a text file all the contents of the MP3 library
- AddRecord: Adds a new record at the end of the MP3 library.
- DeleteRecord: Removes a specific record from the MP3 library, and then shifts the array accordingly.
- UpdateRecord: For a given song record, it updates one or more fields.
- SortRecords: Sorts all the records in the MP3 library according to the name of the song artist.


Now, I cannot for the life of me get the enum to work. It doesn't display correctly, either showing a LARGE number, or repeating the wrong value for each category.
Any help to ANY of the assignment is welcomed. Thanks ahead of time. :)

Here's my code so far:

#include<iostream>
#include<iomanip>
#include<string>
#include<fstream>

using namespace std;

/*enum songCategory {ROCK = 0, ALTERNATIVE = 1, CLASSICAL = 2, SOUNDTRACK= 3, CHILDREN=4, OTHER=5};*/
struct MyLibrary
{
	string albumName;
	string songName;
	string artistName;
	string playTime;
	string genre;
	string albumProducer;
};

void GetLibrary(ifstream& inFile, MyLibrary Library[]);
void PrintLibrary(ofstream& outFile, MyLibrary Library[]);
void PrintToScreen(MyLibrary Library[]);
void AddRecord(ofstream& outFile, MyLibrary Library[]);

const int MAX_SIZE = 200;



int main()
{
	ifstream inFile;
	ofstream outFile;

	inFile.open("MySongLibrary.txt");
	outFile.open("OrganizedLibrary.txt");

	MyLibrary songInfo[MAX_SIZE];

	GetLibrary(inFile, songInfo);
	PrintLibrary(outFile, songInfo);
	//PrintToScreen(songInfo);
	AddRecord(outFile, songInfo);
	


	inFile.close(); 
	outFile.close(); 

	return 0;


}

void GetLibrary(ifstream& inFile, MyLibrary Library[])
{
	for(int i = 0; i < MAX_SIZE; i++)
	{
		string category;

		getline(inFile, Library[i].albumName);
		getline(inFile, Library[i].songName);
		getline(inFile, Library[i].artistName);
		getline(inFile, Library[i].playTime);
		getline(inFile, Library[i].genre);
		/*getline(inFile, category);
			if(category == "ROCK")
				Library[i].genre = ROCK;
			else if(category == "ALTERNATIVE")
				Library[i].genre = ALTERNATIVE;
			else if(category == "CLASSICAL")
				Library[i].genre = CLASSICAL;
			else if(category == "SOUNDTRACK")
				Library[i].genre = SOUNDTRACK;
			else if(category == "CHILDREN")
				Library[i].genre = CHILDREN;
			else if(category == "OTHER")
				Library[i].genre = OTHER;*/
		
		getline(inFile, Library[i].albumProducer);
	}
}


void PrintLibrary(ofstream& outFile, MyLibrary Library[])
{	
	for(int i = 0; i < MAX_SIZE; i++)
	{
		outFile << right << setw(3) << i + 1 << ") ";
		outFile << Library[i].albumName << endl;
		outFile << "     " << Library[i].songName << endl;
		outFile << "     " << Library[i].artistName << endl;
		outFile << "     " << Library[i].playTime << endl;
		outFile << "     " << Library[i].genre << endl;		
		outFile << "     " << Library[i].albumProducer << endl << endl;
	}
}

void PrintToScreen(MyLibrary Library[])
{
	for(int i = 9; i < MAX_SIZE; i++)
	{
		cout << right << setw(3) << i + 1 << ") ";
		cout << Library[i].albumName << endl;
		cout << "     " << Library[i].songName << endl;
		cout << "     " << Library[i].artistName << endl;
		cout << "     " << Library[i].playTime << endl;
		cout << "     " << Library[i].genre << endl;	
		cout << "     " << Library[i].albumProducer << endl << endl;
	}
}

void AddRecord(ofstream& outFile, MyLibrary Library[])
{
	cout << "Please enter the Album Name" << endl;
		cin.getline(Library[i].albumName, albumName);
		outFile << Library[i].albumName;
		cout << "Please enter the Song Name" << endl;
		cin >> Library[i].songName;
}

genre should be of type songCategory in your struct instead of string. Then your other code should work.

Also, you do not need to specify the =0, =1, =2etc in the enum itself since those are the default values so you can have enum songCategory {ROCK,ALTERNATIVE, etc,etc}

It actually is. i just made it string because the enum wasn't working. But before it was songCategory. And the output doesn't work.

Can you put up a sample text file?

Sure:

Queen - Greatest Hits
We Will Rock You
Queen
204
Rock
123 Studios
Queen - Greatest Hits
We Are the Champions
Queen
303
Rock
123 Studios
Queen - Greatest Hits
Another One Bites the Dust
Queen
338
Rock
123 Studios
Queen - Greatest Hits
Don't Stop Me Now
Queen
332
Rock
123 Studios

It works if you get rid of getline(inFile, Library.genre); I didn't try it but it might have worked with inFile >>Library.genre, but mixing getlines and >> can cause trouble. The second argument to getline should be a string.

There are some problems in the addRecord method (you need to probably make a loop in the main method to get additional records and pass in the i value to addRecord and you need to declare albumName locally if you want to read into it.

When i do this:

getline(inFile, Library[i].artistName);
		getline(inFile, Library[i].playTime);
		//inFile >> Library[i].genre;
		//getline(inFile, Library[i].genre);
		getline(inFile, category);
			if(category == "ROCK")
				Library[i].genre = ROCK;
			else if(category == "ALTERNATIVE")
				Library[i].genre = ALTERNATIVE;
			else if(category == "CLASSICAL")
				Library[i].genre = CLASSICAL;
			else if(category == "SOUNDTRACK")
				Library[i].genre = SOUNDTRACK;
			else if(category == "CHILDREN")
				Library[i].genre = CHILDREN;
			else if(category == "OTHER")
				Library[i].genre = OTHER;

		getline(inFile, Library[i].albumProducer);

I get this:

1) Queen - Greatest Hits
We Will Rock You
Queen
204

123 Studios

2) Queen - Greatest Hits
We Are the Champions
Queen
303

123 Studios

3) Queen - Greatest Hits
Another One Bites the Dust
Queen
338

123 Studios


And I do this:

getline(inFile, Library[i].songName);
		getline(inFile, Library[i].artistName);
		getline(inFile, Library[i].playTime);
		inFile >> Library[i].genre;
		//getline(inFile, Library[i].genre);
		/*getline(inFile, category);
			if(category == "ROCK")
				Library[i].genre = ROCK;
			else if(category == "ALTERNATIVE")
				Library[i].genre = ALTERNATIVE;
			else if(category == "CLASSICAL")
				Library[i].genre = CLASSICAL;
			else if(category == "SOUNDTRACK")
				Library[i].genre = SOUNDTRACK;
			else if(category == "CHILDREN")

I get this:

1) Queen - Greatest Hits
We Will Rock You
Queen
204
Rock


2) 123 Studios
Queen - Greatest Hits
We Are the Champions
Queen
303


3) Rock
123 Studios
Queen - Greatest Hits
Another One Bites the Dust
Queen


4) 338
Rock
123 Studios
Queen - Greatest Hits
Don't
Stop Me Now

Your text file has "Rock" but your if statements are testing for "ROCK" so either you have to change the if statement or convert your input to upper case (leave your enum case the same).

Wow can't believe I didn't see that. Fixed.

Unfortunately the output still isn't working...

Here's what I got (changing one to childrens and one to other to test it):

1) Queen - Greatest Hits
    We Will Rock You
    Queen
    204
    0
    123 Studios

 2) Queen - Greatest Hits
    We Are the Champions
    Queen
    303
    4
    123 Studios

 3) Queen - Greatest Hits
    Another One Bites the Dust
    Queen
    338
    5
    123 Studios

EDIT: I should say that was my output file, when you posted the screen printing method it was commented out.

...how? Can you copy that code and paste it here?

...how? Can you copy that code and paste it here?

See my edit on the previous post.
You also have your print to screen method starting from 9 for some reason. The "junk" you are seeing when this is output is due to printing uninitialized variables, which will go away once you feed it the whole songset (or keep track of the number of structs written with a counter and send that number into your printing functions as an upper limit)

commented: Helped a major issue +1

Yeah I fixed the 9.

but what did you do to get that output?
Mine just doesnt work right...

void GetLibrary(ifstream& inFile, MyLibrary Library[])
{
	for(int i = 0; i < MAX_SIZE; i++)
	{
		string category;

		getline(inFile, Library[i].albumName);
		getline(inFile, Library[i].songName);
		getline(inFile, Library[i].artistName);
		getline(inFile, Library[i].playTime);
		//getline(inFile, Library[i].genre);
		getline(inFile, category);
			if(category == "Rock")
				Library[i].genre = ROCK;
			else if(category == "Alternative")
				Library[i].genre = ALTERNATIVE;
			else if(category == "Classical")
				Library[i].genre = CLASSICAL;
			else if(category == "Soundtrack")
				Library[i].genre = SOUNDTRACK;
			else if(category == "Children")
				Library[i].genre = CHILDREN;
			else if(category == "Other")
				Library[i].genre = OTHER;

		getline(inFile, Library[i].albumProducer);
	}
}


void PrintLibrary(ofstream& outFile, MyLibrary Library[])
{	
	for(int i = 0; i < MAX_SIZE; i++)
	{
		outFile << right << setw(3) << i + 1 << ") ";
		outFile << Library[i].albumName << endl;
		outFile << "     " << Library[i].songName << endl;
		outFile << "     " << Library[i].artistName << endl;
		outFile << "     " << Library[i].playTime << endl;
		outFile << "     " << Library[i].genre << endl;		
		outFile << "     " << Library[i].albumProducer << endl << endl;
	}
}

How do I make it print out the string values that are in the Library.genre?

Also, after un-commenting the PrintToScreen, the screen prints out all but the first nine. Why? While the output file has everything correct (except the enum part, it has the corresponding numbers now.)

Ok...*sigh*

I FINALLY got the enum working PERFECTLY. I love you for that.

Now, the PrintToScreen is only printing like the last 42 of the 50 songs I have in the text file, while the output file prints all 50. Why?

here is my current entire code (I know the enum isnt on the PrintToScreen yet...):

#include<iostream>
#include<iomanip>
#include<string>
#include<fstream>

using namespace std;

enum songCategory {ROCK, ALTERNATIVE, CLASSICAL, SOUNDTRACK, CHILDREN, OTHER};
struct MyLibrary
{
	string albumName;
	string songName;
	string artistName;
	string playTime;
	songCategory genre;
	string albumProducer;
};

void GetLibrary(ifstream& inFile, MyLibrary Library[]);
void PrintLibrary(ofstream& outFile, MyLibrary Library[]);
void PrintToScreen(ofstream& outFile, MyLibrary Library[]);
string genreToString(songCategory genre);
void AddRecord(ofstream& outFile, MyLibrary Library[]);

const int MAX_SIZE = 50;



int main()
{
	ifstream inFile;
	ofstream outFile;

	inFile.open("MySongLibrary.txt");
	outFile.open("OrganizedLibrary.txt");

	MyLibrary songInfo[MAX_SIZE];

	GetLibrary(inFile, songInfo);
	PrintLibrary(outFile, songInfo);
	PrintToScreen(outFile, songInfo);
	//AddRecord(outFile, songInfo);
	


	inFile.close(); 
	outFile.close(); 

	return 0;


}

void GetLibrary(ifstream& inFile, MyLibrary Library[])
{
	for(int i = 0; i < MAX_SIZE; i++)
	{
		string category;

		getline(inFile, Library[i].albumName);
		getline(inFile, Library[i].songName);
		getline(inFile, Library[i].artistName);
		getline(inFile, Library[i].playTime);
		getline(inFile, category);
			if(category == "Rock")
				Library[i].genre = ROCK;
			else if(category == "Alternative")
				Library[i].genre = ALTERNATIVE;
			else if(category == "Classical")
				Library[i].genre = CLASSICAL;
			else if(category == "Soundtrack")
				Library[i].genre = SOUNDTRACK;
			else if(category == "Children")
				Library[i].genre = CHILDREN;
			else if(category == "Other")
				Library[i].genre = OTHER;

		getline(inFile, Library[i].albumProducer);
	}
}


void PrintLibrary(ofstream& outFile, MyLibrary Library[])
{	
	for(int i = 0; i < MAX_SIZE; i++)
	{
		outFile << right << setw(3) << i + 1 << ") ";
		outFile << Library[i].albumName << endl;
		outFile << "     " << Library[i].songName << endl;
		outFile << "     " << Library[i].artistName << endl;
		outFile << "     " << Library[i].playTime << endl;
		if(Library[i].genre == 0)
			outFile << "     Rock" << endl;
		else if(Library[i].genre == 1)
			outFile << "     Alternative" << endl;
		else if(Library[i].genre == 2)
			outFile << "     Classical" << endl;
		else if(Library[i].genre == 3)
			outFile << "     Soundtrack" << endl;
		else if(Library[i].genre == 4)
			outFile << "     Children" << endl;
		else if(Library[i].genre == 5)
			outFile << "     Other" << endl;		
		outFile << "     " << Library[i].albumProducer << endl << endl;
	}
}

void PrintToScreen(ofstream& outFile, MyLibrary Library[])
{
	for(int i = 0; i < MAX_SIZE; i++)
	{
		cout << right << setw(3) << i + 1 << ") ";
		cout << Library[i].albumName << endl;
		cout << "     " << Library[i].songName << endl;
		cout << "     " << Library[i].artistName << endl;
		cout << "     " << Library[i].playTime << endl;
		cout << "     " << Library[i].genre << endl;	
		cout << "     " << Library[i].albumProducer << endl << endl;
	}
}

/*void AddRecord(ofstream& outFile, MyLibrary Library[])
{
	cout << "Please enter the Album Name" << endl;
		cin.getline(Library[i].albumName, albumName);
		outFile << Library[i].albumName;
		cout << "Please enter the Song Name" << endl;
		cin >> Library[i].songName;
}*/

Here's what I ran

#include<iostream>
#include<iomanip>
#include<string>
#include<fstream>

using namespace std;

enum songCategory {ROCK = 0, ALTERNATIVE = 1, CLASSICAL = 2, SOUNDTRACK= 3, CHILDREN=4, OTHER=5};
struct MyLibrary
{
	string albumName;
	string songName;
	string artistName;
	string playTime;
	songCategory genre;
	string albumProducer;
};

void GetLibrary(ifstream& inFile, MyLibrary Library[]);
void PrintLibrary(ofstream& outFile, MyLibrary Library[]);
void PrintToScreen(MyLibrary Library[]);
void AddRecord(ofstream& outFile, MyLibrary Library[]);

const int MAX_SIZE = 200;



int main()
{
	ifstream inFile;
	ofstream outFile;

	inFile.open("MySongLibrary.txt");
	outFile.open("OrganizedLibrary.txt");

	MyLibrary songInfo[MAX_SIZE];

	GetLibrary(inFile, songInfo);
	PrintLibrary(outFile, songInfo);
	PrintToScreen(songInfo);
	//AddRecord(outFile, songInfo);
	


	inFile.close(); 
	outFile.close(); 

	return 0;


}

void GetLibrary(ifstream& inFile, MyLibrary Library[])
{
	for(int i = 0; i < MAX_SIZE; i++)
	{
		string category;

		getline(inFile, Library[i].albumName);
		getline(inFile, Library[i].songName);
		getline(inFile, Library[i].artistName);
		getline(inFile, Library[i].playTime);
		//getline(inFile, Library[i].genre);
		//string category;
		getline(inFile, category);
			if(category == "ROCK")
				Library[i].genre = ROCK;
			else if(category == "ALTERNATIVE")
				Library[i].genre = ALTERNATIVE;
			else if(category == "CLASSICAL")
				Library[i].genre = CLASSICAL;
			else if(category == "SOUNDTRACK")
				Library[i].genre = SOUNDTRACK;
			else if(category == "CHILDREN")
				Library[i].genre = CHILDREN;
			else if(category == "OTHER")
				Library[i].genre = OTHER;
		
		getline(inFile, Library[i].albumProducer);
	}
}


void PrintLibrary(ofstream& outFile, MyLibrary Library[])
{	
	for(int i = 0; i < MAX_SIZE; i++)
	{
		outFile << right << setw(3) << i + 1 << ") ";
		outFile << Library[i].albumName << endl;
		outFile << "     " << Library[i].songName << endl;
		outFile << "     " << Library[i].artistName << endl;
		outFile << "     " << Library[i].playTime << endl;
		outFile << "     " << Library[i].genre << endl;		
		outFile << "     " << Library[i].albumProducer << endl << endl;
	}
}

void PrintToScreen(MyLibrary Library[])
{
	for(int i = 0; i < 10; i++)
	{
		cout << right << setw(3) << i + 1 << ") ";
		cout << Library[i].albumName << endl;
		cout << "     " << Library[i].songName << endl;
		cout << "     " << Library[i].artistName << endl;
		cout << "     " << Library[i].playTime << endl;
		cout << "     " << Library[i].genre << endl;	
		cout << "     " << Library[i].albumProducer << endl << endl;
	}
}

/*void AddRecord(ofstream& outFile, MyLibrary Library[])
{
	cout << "Please enter the Album Name" << endl;
		cin.getline(Library[i].albumName, albumName);
		outFile << Library[i].albumName;
		cout << "Please enter the Song Name" << endl;
		cin >> Library[i].songName;
}*/

In terms of the enum, you will more than likely need to go back to strings with another if statement AFAIK.
if(Library.genre==0)
cout<<"Rock"<<endl;
etc.

Check to make sure the output isn't just scrolling off the screen. If you're running it from the command prompt, just do myprogramname > screenout.txt and you'll get an output file.

I love you.

I'll probably have more questions regarding the Add, delete, search, and sort function that I need too. I'll bump the thread up if I have a question regarding those though.

But the enum has been bugging me for DAYS.

I've given you some rep. Thanks man :)

No problem. Post back whenever!

I'm back! Hahaa...

So.. to add a record to the array... this isn't working. Why?
Also, last time I posted a mass of code here is the same except for this part here:
*i = 51 since I have 50 songs in a text file, and to add more means i need it to be in the 51st slot and higher, but lower than the MAX_SIZE of 200.

void AddRecord(ofstream& outFile, MyLibrary Library[])
{
	for(int i = 51; i <= 200; i++)
	{
		string albumName, songName, artistName, playTime, genre, albumProducer;

		cout << "Enter Album Name" << endl;
		cin >> Library[i].albumName;
		outFile << Library[i].albumName;
		cout << "Enter Song Name" << endl;
		cin >> Library[i].songName;
		cout << "Enter Play Time" << endl;
		cin >> Library[i].playTime;
		//cout << "Enter Genre" << endl;
		//cin >> Library[i].genre;
		cout << "Enter Album Producer" << endl;
		cin >> Library[i].albumProducer;
	}

In main, I called PrintLibrary twice once before and once after the addition of the albums, I used a second outfile rather than trying to append with the proper numbering.

int main()
{
	ifstream inFile;
	ofstream outFile;

	inFile.open("MySongLibrary.txt");
	outFile.open("OrganizedLibrary.txt");
	ofstream out2("OrganizedLibraryadded.txt");
	MyLibrary songInfo[MAX_SIZE];

	GetLibrary(inFile, songInfo);
	PrintLibrary(outFile, songInfo);
	//PrintToScreen(outFile, songInfo);
	AddRecord(outFile, songInfo);
	//PrintToScreen(outFile,songInfo);
	PrintLibrary(out2,songInfo);

	inFile.close(); 
	outFile.close(); 

	return 0;


}

Here is a modified version of the method

void AddRecord(ofstream& outFile, MyLibrary Library[])
{
	for(int i =4 /*(MODIFY FOR NUM OF RECORDS PULLED IN)*/; i <MAX_SIZE ; i++)
	{ //if there were 50 records already, it would be #0 to #49 so start with 50

		string genre;
		cout << "Enter Album Name" << endl;
		getline(cin, Library[i].albumName);
		cout << "Enter Song Name" << endl;
		getline(cin, Library[i].songName);
		cout <<"Enter Artist Name"<<endl; //you had forgotten this 
                                                                         //one in this method
		getline(cin, Library[i].artistName);
		cout << "Enter Play Time" << endl;
		getline(cin, Library[i].playTime);
		cout << "Enter Genre" << endl;
		getline(cin, genre);
		
			if(genre == "Rock")
				Library[i].genre = ROCK;
			else if(genre == "Alternative")
				Library[i].genre = ALTERNATIVE;
			else if(genre == "Classical")
				Library[i].genre = CLASSICAL;
			else if(genre == "Soundtrack")
				Library[i].genre = SOUNDTRACK;
			else if(genre == "Children")
				Library[i].genre = CHILDREN;
			else if(genre == "Other")
				Library[i].genre = OTHER;
			else
				Library[i].genre = OTHER; //or reject bad user input
	
		
		cout << "Enter Album Producer" << endl;
		getline(cin,Library[i].albumProducer);
	}
	

}

I'd stick with the getlines to be consistent. I was having some trouble with the cin >> which could have been alleviated with cin.ignore() but I didn't bother.

Well, while doing the delRecord function, I've run into an error upon execution. Some sorta runtime error I don't know what's causing it.
Here's my code for it:

void DelRecord(ofstream& DelOutFile, MyLibrary Library[])
{
	int i;											// number that corresponds to array delete
	MyLibrary songInfo[MAX_SIZE];	
	
	cout << "Choose number the corresponds to record you would like to delete." << endl;
	cin >> i;

	while(i < 50)
	{
		Library[i] = Library[i + 1];
		i++;
	}
	
}

I made some changes, commented below:

void DelRecord(MyLibrary Library[])  //instead of passing in an output file, just use the 
                                                       //PrintLibrary up above
{
	int i;	
	//MyLibrary songInfo[MAX_SIZE];  don't need to redeclare this here	
	
	cout << "Choose number the corresponds to record you would like to delete." << endl;
	cin >> i;
	i--; //convert users entry into zero-based index
	while(i <MAX_SIZE-1) //since you are moving i+1 to i
	{
		
		Library[i] = Library[i + 1];
		i++;
	}
	
}

Oh wow. I just simply overlooked the fact that the array is zero based. Wow. I feel stupid. :|

But thanks once again!

Hmm....I'm really surprised this part isn't working. I looked at Google, and saw people have problems with the "getline()" a lot.

Every time I execute this part, for the albumName, it skips the entire getline part and won't let me input.
For the songName part, I did it differently, adding a cin >>, and it lets me input, but outputs it as blank.

What is intriguing is that I did this same cout << "ask question" and getline(cin, Library....) in my AddRecord function earlier and it worked flawless. Why doesnt it work now?

:'(


void UpdateRecord(ofstream& updatedOutFile, MyLibrary Library[])
{
	int i;										// number user selects as album to change
	char answer;								// letter to choose what to update
	string albumName, songName, artistName, playTime, genre, albumProducer;

	cout << "Enter the number that corresponds to the album you would like to change." << endl;
	cin >> i;

	i--;					// Decrement since array is zero-based

	cout << "Change the Album Name. Y or N?" << endl;
	cin >> answer;
	switch (answer)
	{
	case 'Y':
	case 'y':
		cout << "Enter Album Name" << endl;
		getline(cin, Library[i].albumName);
	case 'N':
	case 'n':
		break;
	}

	cout << "Change the Song Name. Y or N?" << endl;
	cin >> answer;
	switch (answer)
	{
	case 'Y':
	case 'y':
		cout << "Enter Song Name" << endl;
		cin >> songName;
		getline(cin, songName);
		Library[i].songName = songName;
	case 'N':
	case 'n':
		break;
	}

Put a cin.ignore(); before each of your getline statements (and get rid of the extra cin for songName). That will get rid of the extra \n character from when you press enter for your cin>>answer; prompt (since answer is only expecting 1 character, the \n is left in the buffer and fouls up your getline). I'm sure you put them in there for testing other options but you don't need to redeclare albumName, etc in this function. In testing this, I again put an extra PrintLibrary() call after I called UpdateRecord(); instead of passing in the ofstream directly.

commented: Damn helpful. +1

I see. It works now, thanks.

So, whenever I ask a user a question that requires a single variable (like 'Y', or '123'...) I have to use a cin.ignore before using a getline to ignore that \n?

Interesting...that'll explain why the getline worked for the AddRecord and not here at first, since the AddRecord function didn't require any previous input.

I see. It works now, thanks.

So, whenever I ask a user a question that requires a single variable (like 'Y', or '123'...) I have to use a cin.ignore before using a getline to ignore that \n?

There are other situations in which junk can get stuck in the buffer. At the top of the C++ forum there's a sticky article on flushing the streams, that'll give you some idea of the different situations. 123 isn't a single character, it's a string. I just meant that when cin is expecting one char (as that's all that will fit) and you hit enter after, that's really 2 characters, so the second one sticks around.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.