Inserting into linked list
I'm having a problem inserting a new node into a linked list that I've already made and sorted. The original list was made from a file, now the user has the option to add nodes to the list.
Here's the code for insertion (where I think the problem lies), and more explanation of the problems I'm having follow:
The first problem is that when the prompt shows up asking to add a person, if you input yes, the user is then prompted for the name, immediately followed by prompt for the ID, with no chance to input the name. The user is allowed to input the ID, then prompted for address and inputs that, then is prompted about adding more.
//Query user to add people
cout << "Would you like to add a person to this list? yes / no" << endl;
cin >> add_resp;
while (add_resp == "yes")
int keepgoing = 1;
while (keepgoing == 1)
cout << "Enter the name for the person to be added as \"last_name, first_name\"" << endl;
newNode = last;
newNode -> name = name;
cout << "Enter the ID number for " << name << endl;
newNode -> ID = ID;
cout << "Enter the address for " << name << endl;
newNode -> address = address;
cout << "Would you like to add another person? yes / no" << endl;
if (add_resp == "no")
keepgoing = 0;
Why is this happening? Why is the user never given the opportunity to enter the name? When you respond to the second query about adding a person (after you've added one) you are able to input all info just fine.
Secondly, the insertion overwrites one of my previous nodes. I have 6 from the text file, and throughout I only have six, one is continuously deleted (if I add more than 1 person, it overwrites one of the original nodes and keeps overwriting itself.).
Now I know the last part is because I haven't inserted it correctly and set it to point to the next node, I've tried a few different ways and have been unsuccessful.
How can I fix this!?