student information

i want to store information of student why this not working properly code below down here..

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
  #include<iostream>
using namespace std;
struct node
{
	int age;
	double baln;
	node *next;
};
class list 
{

private:
	node *start, *last;
public:
	void begin(int age, double baln);
	list()
	{
		start = NULL;
		last = NULL;
	}
};



void list::begin(int age, double baln)
{

	node *temp = NULL;
	temp->age = age;
	temp->baln = baln;
	temp->next = NULL;
	if (start == NULL)
	{
		start = temp;
		last = temp;
	}
	else
	{
		last->next = temp;
		last = temp;
	}
	cout << "Element Inserted at beginning" << endl;
}
int main()
{

	while (1)

	{
		list l;
		int a, ch; double b;
		cout << "Enter your choice \n";
		cin >> ch;
		switch (ch)
		{
		case 1:
		{

				  cout << "enter age\n";
				  cin >> a;
				  cout << "enter  balance \n";
				  cin >> b;
				  l.begin(a, b);
				  break;
		}
		case 2:
		{
				  break;
		}
		default:
		{
				   cout << "wrong input\n";
		}
		}

	}

	system("pause");

I would start by making your input loop functional. Then repost your code if you get stuck.
this is a college programming excercise.
you must do these simple program by own.
in Linked List topics always draw the simple flow of program of pice of paper to
clarify it .
draw the flow chart of code to avoid simple errors.

this is your corrected code:
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118

#include<iostream>
#include <stdio.h>
using namespace std;


struct node
{
	public:
		int age;
		double baln;
		node *next;
};

class list 
{
	
	private:
		node *start, *last;
	public:
	
		void begin(int a, double b);
		
		void print (){
			node *h;
			if(start==0){
				cout<<"list is empty";
				return;
			}
			
			h=start;
			while(h){
				cout<< "age:"<<h->age<<"   "<<"balance:"<<h->baln<<endl;
				h=h->next;
				}
			cout<<endl<<endl;	
			}
			
		list()
		{
			start = NULL;
			last = NULL;
		}
};



void list::begin(int a,double b)
{
	node *temp;
	temp = new node;
	
	temp->next = 0;
	
	if (!start){
		start =  last = temp ;		
		cout << "Element Inserted at beginning of list" << endl<<endl;
	}
	else{
		last->next = temp;
		last = temp;
		cout << "Element Inserted to last piont of list" << endl<<endl;
	}

	last->age = a;
	last->baln = b;	

}

int main(int argc,char **argv)
{

	list l;///you place it in while (1) 
	/// create a new list in every iteration--- Fulse
	
	int a, ch; double b;
		
	while (1){

		
		cout << "1. Add Node to list \n";
		cout << "2. Print List \n";
		cout << "3. Exit \n";
		cout << "Enter your choice \n";
		cin >> ch;
		
		switch (ch){
			case 1:	{
						cout << "enter age\n";
						cin >> a;
						cout << "enter  balance \n";
						cin >> b;
						l.begin(a,b);
						break;
					}
			
			case 2: {
						cout<<"print\n";
						l.print();	
						break;
					}
				
			case 3: {
						return 0;
						break;
					}		
			default:{
						cout << "wrong input\n";
					}
				}

	}

	getchar();
	return 0;
	
}


feel free to ask any other questions, on this topic or my account
Topic archived. No new replies allowed.