//*****************************************************************************
////  Course:             COMS 2203 Foundations of Computer Programming II Sect. 2
////  Semester:           Fall 2004
////  Assignment Number:  #9                             
////  Author Name:        DarC KonQuesT                        
////  Date Written:       November 4, 2004
////                                                         
////  Description of Program:                              
////  This program creates a linked list of employee records (id and name).  It     
////  reads repeatedly, creating nodes, until a zero is entered for ID#.                             
////*****************************************************************************

#include <iostream>
#include <string>
#include <cstddef>
using namespace std;

// linked-list node structure
struct NodeType {
  int       id;    // employee id
  string    name;  // employee name (last name)
  NodeType *next;
};

int main()
{
  NodeType *head = NULL;
  NodeType *tail = NULL;
  NodeType *p;
  int id;
  string name;
 
 //set everything up 
  p = new NodeType;
  cout << endl << "Enter ID number (or 0 to quit): ";
  cin >> id;
  p->id = id;
  if(p->id == 0) return 0;
  cout << endl << "Enter last name: ";
  cin >> name;
  p->name = name;
  head = tail = p;
  
//enter loop with variables prepared - exit if id = 0
  while(id != 0)
  {
    p = new NodeType;
    cout << endl << "Enter ID number (or 0 to quit): ";
    cin >> id;
    if(id == 0) break;
    p->id = id;
    cout << endl << "Enter last name: ";
    cin >> name;
    p->name = name;
    tail->next = p;
    tail = p;
    
  }
  
  
  p = head;
  cout << endl;
  while(p != NULL)
  {
    cout << p->id << "  " << p->name << endl;
    p = p->next;
  }
  return 0;
}

