int main()
{
node *curr = new node;
node *head = new node;
//**********************************************
//Variable to deteermine whether to repeat or not
//***********************************************
char ContinuationFlag = 'Y';
char Nextchar = '0';
node *temp = new node;
while (toupper(ContinuationFlag) == 'Y')
{
cout<<"Input the tracking number of the animal"<<endl;
cin>>temp->trackNo;
cout<<"Input the name of the animal"<<endl;
cin>>temp->animalName;
cout<<"Input the charge for boarding the animal"<<endl;
cin>>temp->boardCharge;
insert(temp);
cout<<endl<<"Do you wish to enter another item? "<<endl;
cout<<"Enter 'Y' or 'N' "<<endl;
cin>>ContinuationFlag;
}
showList(temp);
return 0;
}
void insert(node *curr)
{
node *temp = new node;
node *head = new node;
When you reply to a topic or create a topic there is a format section to the right of the text area... the symbol <> will produce a code tag which when you paste your code in between the tag will output the code like this
line 17: void insert(node *head, node *curr);
line 24: remove that line, you dont need curr
line 26: head = NULL; // initialize head
line 51: temp = temp->next = NULL; //add this before you close the loop
//you have to create a new node for every iteration.
node *temp;
while (toupper(ContinuationFlag) == 'Y')
{
temp = new node;
//...
}
line 46: insert(head,temp); //new insert function
line 53: showList(head); //print from first.
//complete makover of insert
void insert(node *head,node *curr)
{
if(head == NULL) //if there is no head
{
head = curr;
}
else
{
//look for last node.
// I assume you are adding to the end of the list
node *temp = new node;
node *previous = new node;
for(temp = head; temp != NULL; temp = temp->next)
{
previous = temp;
}
previous = curr;
}
}
#include <iostream>
#include <string>
usingnamespace std;
struct node
{
int trackNo;
string animalName;
double boardCharge;
node *next;
};
//***********************
//Function prototypes
//***********************
void insert(node *head, node *curr);
void showList(node *head);
int main()
{
node *head = new node;
head = NULL;
//**********************************************
//Variable to deteermine whether to repeat or not
//***********************************************
char ContinuationFlag = 'Y';
node*temp;
//********************
//input of information
//********************
while (toupper(ContinuationFlag) == 'Y')
{
temp = new node;
cout<<"Input the tracking number of the animal"<<endl;
cin>>temp->trackNo;
cout<<"Input the name of the animal"<<endl;
cin>>temp->animalName;
cout<<"Input the charge for boarding the animal"<<endl;
cin>>temp->boardCharge;
//*******************************
//send to function that captures list
//**********************************
insert(head,temp);
//*******************
//ask user if they want to continue
//******************************
cout<<endl<<"Do you wish to enter another item? "<<endl;
cout<<"Enter 'Y' or 'N' "<<endl;
cin>>ContinuationFlag;
}
//*********************************
//when user is finish, displays list
//*********************************
showList(head);
return 0;
}
void insert(node *head, node *curr)
{
if(head == NULL)
{
head = curr;
}
else
{
node *temp = new node;
temp =NULL;
temp=head;
temp=temp->next;
curr = temp->next;
head=curr;
}
return;
}
void showList(node *head)
{
node *curr = new node;
curr=head;
while(curr != NULL)
{
cout<<curr->trackNo<<endl;
cout<<curr->animalName<<endl;
cout<<curr->boardCharge<<endl;
curr=curr->next;
}
}