[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 183
  • Last Modified:

What is wrong here?

I get no compile errors I get a weird output for x

Here is my code:


#include <iostream>
 
using namespace std;
 
int main()
{
	struct Point
	{
		int x;
		int y;
		Point *next;
	};
 
	Point *first, *last, *newNode;
	int num;
	int count = 0;
 
	first = NULL;
	last = NULL;
 
	cout << "Enter how many integers to enter: ";
	cin >> count;
	cout << endl;
 
	for (int i = 0; i < count; i++)
	{
		cout << "Enter for X: ";
		cin >> num;
		cout << endl;
 
		newNode = new Point;
		newNode->x = num;
 
		cout << "Enter for Y: ";
		cin >> num;
		cout << endl;
		
		newNode = new Point;
		newNode->y = num;
 
		newNode->next = NULL;
 
		if(first == NULL)
		{
			first = newNode;
			last = newNode;
		}
		else
		{	
			last->next = newNode;
			last = newNode;
		}
	}
 
	cout << "Linked List in the order entered: ";
	
	for (int i = 0; i < count; i++)
	{
		cout << first->x << " ";
		cout << first->y << endl;
		first = first->next;
	}
 
	cout << endl;
 
}

Open in new window

0
jschmuff
Asked:
jschmuff
1 Solution
 
zveljkovicCommented:
Hi. I wanted to post on your deleted topic too :)
Error is in line 38
you should delete it.
0
 
jschmuffAuthor Commented:
Thanks man, your awesome. I couldn't figure out what was wrong here.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now