I'm having to create a program that uses a linked list to ask for X & Y points and stores them in a linked list and then displays those results.
My problem here is when it gives me the output I only see the last 2 entries I've made. It's not storing all the values I've inputted. I need a push in the right direction.
Thanks
#include <iostream>
#include <list>
using namespace std;
int main()
{
struct node
{
int x;
int y;
node *nxt;
};
node *start_ptr, *temp, *current;
temp = new node;
start_ptr = NULL;
int numPoints = 0;
int i = 0;
cout << "Welcome to my Linked List Project" << endl;
cout << endl;
cout << "How many points do you wish to enter? ";
cin >> numPoints;
do
{
cout << "Enter a X value: ";
cin >> temp->x;
i++;
cout << "Enter a Y value: ";
cin >> temp->y;
//temp->nxt = NULL;
start_ptr = temp;
}
while (i < numPoints);
current = start_ptr;
while(current != NULL)
{
cout << "Here are your X values: " << current->x << " ";
cout << endl;
cout << "Here are your Y values: " << current->y << " ";
cout << endl;
current = current->nxt;
}
}