Problem with Displaying IDs

Ok so I got most of my code working except for display aka ListNodes.

I currently have:
1
2
3
4
5
void ListNodes(A *list)
{
         while(list) cout<<list->key<<endl;
                      list->next;
}


This is my main:

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
59
60
61
62
63
64
65
66
67
68
69
70
71
int main()
{
    int x;
    A *N,*l;
    char C;
    C = Menu();
    while(1)
    {
     switch (C)
     {
     case 'C':
	 case 'c':
        cout<<"Please enter in ID:";
        cin>>x;
		l = CreateNode(0);
		if(l != NULL)
		{
		     InsertNode(l);
		     C = Menu();
        }
		else cout<<"Error."<<endl;
		break;
	 case 'D':
	 case 'd':
        cout<<"Please enter in ID:"<<endl;
        cin>>x;
        l = CreateNode(0);
        	if(l != NULL)
		{
		DeleteNode(l,x);
		C = Menu();
        }
        else cout<<"Error."<<endl;
        C = Menu();
		break;
	 case 'L': //starting List
	 case 'l':
        cin>>x;
         l = CreateNode(0);
        	if(l != NULL)
		{
        ListNodes(l); //I believe the value is wrong here but don't know
        C = Menu(); 
        }
        else 
        cout<<"There are no IDs."<<endl;
        C = Menu(); //Ending List
		break;
	 case 'U':
	 case 'u':
        cout<<"Please enter in ID:"<<endl;
        cin>>x;
        l = CreateNode(0);
        if(l != NULL)
        {
		     UpdateNode(l);
		     C = Menu();
        }
		     else cout<<"Error."<<endl;
		     cout<<"Please try again."<<endl;
		     C = Menu();
		break;
	 case 'E':
	 case 'e':
		cout<<"\n Thank you."<<endl;
		cout<<"\n\n Have a nice day."<<endl;
		exit(0);
		break;
      }
     }
}


I'm not sure if my ListNodes is the problem or my code in main is.
I just want it to list all my IDs I punched in for create. Is there an easier way to list these and I'm making it too hard? Should I use an array type of display?
Last edited on
It is really hard to answer questions when posters don't post a complete program. I do not know what many of the functions in you program look like.

What do you expect this to do exactly? I see a while loop that might never end. I'm not sure what the second statement does but it doesn't appear to be part of the loop.
1
2
3
4
5
void ListNodes(A *list)
{
         while(list) cout<<list->key<<endl;  // will this loop ever terminate?
                      list->next; // what does this line do?
}


The tabbing is messed up within your code tags. You should reformat more neatly so that it is easier to read. It is hard to find all of the case statements.
Last edited on
Topic archived. No new replies allowed.