Quick help

My assignment is: Unordered with header and trailer nodes

This is what I have:

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
72
73
74
75
76
77
78
79
80
81
82
83
84
#include <iostream>

#include "unorderedLinkedList.h" 
using namespace std;

int main()
{
	char choice;
	cout << "What would you like to do? " << endl;
	cout << "I - Insert a node" << endl;
	cout << "D - Delete a node" << endl;
	cout << "S - Search a node" << endl;
	cout << "P - Print a node" << endl;
	cout << "E - End" << endl;
	cin >> choice;

	unorderedLinkedList<int> list1;          
    int num;                                        

	switch(choice)
	{
	case 'I':
                  
    cout << "Enter integers ending " 
         << "with -999" << endl;                    
    cin >> num;                                     

    while (num != -999)                             
    {                                               
        list1.insertLast(num);                      
        cin >> num;                                 
    }                                               

    cout << endl;                                   

    cout << "The list: ";                     
    list1.print();                                  
    cout << endl;                     
		break;


	case 'P':
		    cout << "List: ";                     
    list1.print();                                 
    cout << endl;                                   
    cout << "Length of List: " 
         << list1.length() << endl;    
		break;

	case 'D':
	cout << "Enter the number to be "
         << "deleted from the list: ";                            
    cin >> num;                                     
    cout << endl;                                   

    list1.deleteNode(num);                          
	
    cout << "After deleting " << num 
         << "on the list we have: " << endl;                    
    list1.print();                                  
    cout << endl;   
		break;
	case 'S':
  cout << "Enter a number to be searched "
         << "for: ";                            
    cin >> num;                                    
    cout << endl;                                  
          
    cout << "Searching for " << num 
         << " on the list: " << endl;                     
    list1.print();  
	cout << endl; 
	list1.search(num);    
    cout << endl;      
		break;
	case 'E':
		break;
	default:
//
		break;
	}

	return 0;
}


Everytime I run it and enter "I" to enter the integers into the list after i type -999 and enter it crashes the program.

I need to make it so I can go back to the menu to show it by printing it and same for searching and deleting.
Last edited on
I need help with this small assignment my teacher gave me.

What help do you need? I don't see a question or a problem in your post.
I just updated the topic. Now I'm stuck

This is the original program I am trying to convert to make work with switch statements.

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

  
#include <iostream>                                 
#include "unorderedLinkedList.h"                    
 
using namespace std;                                

int main()                                          
{                                                   
    unorderedLinkedList<int> list1;          
    int num;                                       

    cout << "Enter integers ending " 
         << "with -999" << endl;                    
    cin >> num;                                     

    while (num != -999)                             
    {                                               
        list1.insertLast(num);                      
        cin >> num;                                 
    }                                               

    cout << endl;                                   

    cout << "The list: ";                     
    list1.print();                                  
    cout << endl;                                                      

    cout << "Enter the number to be "
         << "deleted from the list: ";                            
    cin >> num;                                     
    cout << endl;                                   

    list1.deleteNode(num);                          
	
    cout << "After deleting " << num 
         << "on the list we have: " << endl;                    
    list1.print();                                  
    cout << endl;      
	
	//added
	
	    cout << "Enter a number to be searched "
         << "for: ";                            
    cin >> num;                                    
    cout << endl;                                  
          
    cout << "Searching for " << num 
         << " on the list: " << endl;                     
    list1.print();  
	cout << endl; 
	list1.search(num);    
    cout << endl;      
	
    return 0;                                       
}                        
Last edited on
I don't see anything suitable for a switch statement in your most recent post.
Your original post post at least had a menu and a switch statement.

The random indentation in your original post makes it very hard to read.
I would suggest breaking your original program up into functions. Each branch of your switch statement should call one function.

I see you've now added a description of the problem you were having to your original post.

As for why your original program is crashing, I don't see anything obvious in the code you posted. The problem could be in your unorderedLinkedList class, which you haven't shown.

As for going back to the menu, you need an outer loop which will do that.


Topic archived. No new replies allowed.