Hello,
I was wondering if I could get a little help fixing my issue. The project we were given in class was to create a phonebook app that asks the user to input the first and last name, number, and email of a contact. Then it saves to a file (book.txt). The repeats the action until the user ends the loop. Everything works if you only input 1 contact. But if you enter 2 contacts the phone number messes up when the user cin >> phonenumber[count] but everything (name and email) turns out fine. I knew the problem is i ask the user to cin the phonenumber like ###-###-#### and the "-" throw everything off because when I enter it withought the "-" it works fine.
What happens is if i enter 555-555-5555 for phonenumber[0] and then 555-000-0000 (or any number) phonenumber[0] becomes 555-555-5555555-000-0000 and phonenumber[1] stays 555-000-0000. and so on as i add more contacts.
[int main()
{
int count, number = 0;
char Fname[100][NAMES], Lname[100][NAMES], PhoneNumber[100][NUMBER], email[100][MAIL], selected;

//Call all data from file

ifstream inFile;
inFile.open("book.txt");
inFile >> count;
while (inFile >> Fname[number] >> Lname[number] >> PhoneNumber[number] >> email[number])
{
number++;
}
inFile.close();

displayMenu(Fname, Lname, PhoneNumber, email, count);

return 0;
}

void displayMenu(char Fname[][NAMES], char Lname[][NAMES], char PhoneNumber[][NUMBER], char email[][MAIL], int count )
{
cout << endl << setw(5) << left << "A)" << "Add Contact" << endl;
cout << setw(5) << left << "D)" << "Delete Contact" << endl;
cout << setw(5) << left << "F)" << "Find and Display Contact" << endl;
cout << setw(5) << left << "L)" << "List Contacts" << endl;
cout << setw(5) << left << "S)" << "Save Contacts" << endl;
cout << setw(5) << left << "E)" << "Exit" << endl << endl;
selection(Fname, Lname, PhoneNumber, email, count);

}

void selection(char Fname[][NAMES], char Lname[][NAMES], char PhoneNumber[][NUMBER], char email[][MAIL], int count )
{
\
char selected;
bool valid = false;
while (valid != true)
{
cin >> selected;
switch(selected)
{
case 'A':
case 'a':valid = true, addContact(Fname, Lname, PhoneNumber, email, count);
break;
case 'D':
case 'd': valid = true, deleteContact(Fname, Lname, PhoneNumber, email, count);
break;
case 'F':
case 'f': valid = true, displayContact();
break;
case 'L':
case 'l': valid = true, listContacts();
break;
case 'S':
case 's': valid = true, saveContacts(Fname, Lname, PhoneNumber, email, count);
break;
case 'E':
case 'e': valid = true, exitPhonebook();
break;
}
}
}

void addContact(char Fname[][NAMES], char Lname[][NAMES], char PhoneNumber[][NUMBER], char email[][MAIL], int count )
{
cout << count;
if (count < 100)
{
cout << "First Name of Contact: ";
cin >> Fname[count];

cout << "Last Name of Contact: ";
cin >> Lname[count];

cout << "Phone Number of Contact (###-###-####): ";
cin >> PhoneNumber[count];

cout << "Email of Contact: ";
cin >> email[count];
count++;
}

else
{
cout << "Phone Book is full. Please delete a contact if you wish to add a new one." << endl;
}
displayMenu(Fname, Lname, PhoneNumber, email, count);]

I was hoping i could get some help. Thanks in advance :-)