Please help me to get out of this problem !

Dec 27, 2016 at 1:00pm
Hello everyone,

I am coding a simple Railway reservation system.
I don't know what should I write to take input from user about "Name" and respective "Ages" of Passengers.

I am using Turbo C++

Thanks

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

#include<iostream.h>
#include<conio.h>
#include<string.h>


class railway
	{	public:
		long int tn;
		int pno,age;
		char sst[30];
		char dst[30];
		char pnam[30];
		char date[15];
		void getdata();
		void display();

	};
void railway::getdata()
	{
		cout<<"\nEnter Train Number " ;
		cin>>tn;
		cout<<"\nEnter Source Station ";
		cin>>sst;
		cout<<"\nEnter Destination Station ";
		cin>>dst;
		cout<<"\nEnter the date of Journey ";
		cin>>date;
		cout<<"\nEnter No. of Passangers ";
		cin>>pno;
		for(int i=0;i>pno;i++)
			{
				cout<<"Enter Name of Passenger"<<i+1;
				cin>>pname[i];
				cout<<"Enter Age of Passenger "<<i+1;
				cin>>age[i];

			}
			getch();
	}
void railway :: display()
	{
		cout<<"\nDate : \t\t"<<date;
		cout<<"\nTrain Number : \t"<<tn;
		cout<<"\nFrom : \t\t"<<sst;
		cout<<"\nTo : \t\t"<<dst;
		cout<<"\nNo. Of Passengers : \t\t"<<pno;
	}
void main()
	{       clrscr();
		int fare;
		char name[30];
		railway a;
		cout<<"** Welcome to Railway Reservation System **";
		a.getdata();
		a.display();


        }


Dec 27, 2016 at 1:03pm
I think line 31 should be:
for(int i=0;i<pno;i++)
Dec 27, 2016 at 1:06pm
The Error now is "Invalid indirection"
Dec 27, 2016 at 1:12pm
OUTPUT : http://imgur.com/a/pd3mO

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
//This C++ program "Railway Reservation System" is Programmed by =
//Name    = Himanshu Singh
//Class   = 12th A1
//Roll No = 37
//CENTRAL HINDU BOYS SSS BHU KAMACHHA VARANASI (UP)

#include<iostream.h>
#include<conio.h>
#include<string.h>


class railway
	{	public:
		long int tn;
		int pno;
		char sst[30];
		char age[10];
		char dst[30];
		char pname[30];
		char date[15];
		void getdata();
		void display();

	};
void railway::getdata()
	{
		cout<<"\nEnter Train Number " ;
		cin>>tn;
		cout<<"\nEnter Source Station ";
		cin>>sst;
		cout<<"\nEnter Destination Station ";
		cin>>dst;
		cout<<"\nEnter the date of Journey ";
		cin>>date;
		cout<<"\nEnter No. of Passangers ";
		cin>>pno;
		for(int i=0;i<pno;i++)
			{
				cout<<"Enter Name of Passenger"<<i+1;
				cin>>pname[i];
				cout<<"Enter Age of Passenger "<<i+1;
				cin>>age[i];

			}
			getch();
	}
void railway :: display()
	{
		cout<<"\nDate : \t\t"<<date;
		cout<<"\nTrain Number : \t"<<tn;
		cout<<"\nFrom : \t\t"<<sst;
		cout<<"\nTo : \t\t"<<dst;
		cout<<"\nNo. Of Passengers : \t\t"<<pno;
	}
void main()
	{       clrscr();
		int fare;
		char name[30];
		railway a;
		cout<<"** Welcome to Railway Reservation System **";
		a.getdata();
		a.display();




	}






Last edited on Dec 27, 2016 at 1:14pm
Dec 27, 2016 at 1:30pm
I am a beginner also, but I dont think you should be calling the two functions on line 21 and line 22 as you are calling them in main from the railway object.

Comment out line 21 and line 22 and then run your program
Last edited on Dec 27, 2016 at 1:31pm
Dec 27, 2016 at 1:38pm
I am using class.

There is not any issue.

After doing what you said I am getting lloooooots of errors.
Dec 27, 2016 at 1:43pm
Can you please tell me what should I use to store the names of Passengers ?
Dec 27, 2016 at 2:08pm
Can you please tell me what should I use to store the names of Passengers ?
You could use separate arrays for age and name, like this:
1
2
    int  age[100];
    char pname[100][30];

or alternatively, define a separate class called person or passenger which will store the age and name, and then use an array of passengers inside the railway class.
Dec 27, 2016 at 2:12pm
Thanks a lot... Let me give a try.
Dec 28, 2016 at 3:47am
is this problem solved ?
Topic archived. No new replies allowed.