Linked list

I'm trying to make a linked list that will ask the user for the total length then output the values in order on the screen. bellow is what I have, any help would be appreciated.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include "stdafx.h"
#include <iostream>
#include <new>
using namespace std;

struct listrec
{
	listrec *prev;
	float  value;
	listrec *next;
	
};

int main()
{

	
	listrec * A;
	listrec * head=NULL;
	listrec * tail=NULL;
	float value, B=0;
	A = new listrec;

	cout << "How many values would you like in the list ?" << endl;
	cin >> value;
	if (value < 0)										//Checks for a value of zero or greater
	{
		cerr << "******You entered a value less than zero, the program will now end******" << endl;
		exit(1);
	};
	cout << "You have selected " << value << " values" << endl;


	value = B;
	value = 0;
	while (value != B)
		{

			A->value;
			tail = A;

			A = new listrec;
			A->prev = NULL;
			A->value;
			A->next = NULL;
			head = A;
			tail= A;
			cout << "Your numbers are: " << value << endl;
			value++;
			

			cout << "The program is Complete" << endl;
	};

		return 0;

	
};
First of all, please elaborate on what you intent to do.

Secondly, you do this:
float value, B=0;

then this:
1
2
value = B;
	value = 0;


So, why do hope to see this loop execute?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
while (value != B)
		{

			A->value;
			tail = A;

			A = new listrec;
			A->prev = NULL;
			A->value;
			A->next = NULL;
			head = A;
			tail= A;
			cout << "Your numbers are: " << value << endl;
			value++;
			

			cout << "The program is Complete" << endl;
	};
Thank you sir, I think I got caught in a loop

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
	while (value != B)
		{
			
			A->value;
			tail = A;
			
			A = new listrec;
			A->prev;
			A->value;
			A->next;
			head = A;
			tail= A;
			cout << "Your numbers are: " << B+1 << endl;
			B++;
			
			

			cout << "The program is Complete" << endl;
	};
He is saying that you assign 0 to B on line 21. Then you assign B to value on line 34. Right now, value == B. On line 35, you assign 0 to value, but since B is also 0, value == B.

Your loop will run if value != B. Since value == B when we get to your loop, it will never run.
you get the user input at line 25 and stored it to "value". then in line 34 you overwrite it! here user input is vanished.

and you have some incomplete statements like A->value;
In short, the whole design has lots of logical problems, as stated above.
Thanks I got that part about the value to 0 and removed it
you should try singly linked list before trying doubly linked list.
Topic archived. No new replies allowed.