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.
#include "stdafx.h"
#include <iostream>
#include <new>
usingnamespace 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;
};
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.