HELP hotel program

Hello, I wrote the program for a hotel using the stack, the user enters the full name and then enter a room with one bed or two and then prints the program full name with the desired option and then the price but I want to develop the program by adding floors floor contains a single room and floor double rooms and floor room luxury or property but when you add the function does not apply to the program, I want to help you add this program to change without happen mistakes .. Thank you
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
#include<iostream.h>
#include<string.h>
int room[10],price;
int top;
struct hotel{
int bed;
char firstname[30],lastname[30];
hotel *next;};
typedef struct hotel *ptr;
typedef ptr list;
hotel *push(list h,char fn[30],char ln[30],int b)
{hotel *temp;
if(h==NULL)
{h=new hotel;
strcpy(h->firstname,fn);
strcpy(h->lastname,ln);
h->bed=b;
h->next=NULL;}
else
{temp=new hotel;
strcpy(temp->firstname,fn);
strcpy(temp->lastname,ln);
temp->bed=b;
temp->next=h;
h=temp;}
return h;}
void push1(int r)
{if(top==10)
{cout<<"error:stack overflow \n";}
else
{top++; room[top]=r;}}
void print(list h,int b)
{hotel *temp=h;
while(temp!=NULL)
{cout<<"name is:"<<temp->firstname<<"\t"<<temp->lastname<<endl;
if(b==1)
{cout<<"price is: 1000$"<<endl;}
if(b==2)
{cout<<"price is: 1500$"<<endl;}
temp=temp->next;}}
int pop1()
{if (pop1<0)
{cout<<"error:stack underflow \n";}
else
{return room[top--];}}
hotel *pop(list h)
{hotel *temp;
temp=h;
h=temp->next;
delete temp;
return h;}
void main()
{int b;
char fn[30],ln[30];
top=-1;
list head=NULL;
cout<<"enter your full name:";
cin>>fn>>ln;
cout<<"enterthe number of bed 1 or 2:";
cin>>b;
head=push(head,fn,ln,b);
print(head,b);
push1(1);
cout<<"room is:";
cout<<pop1();
head=pop(head);
}[code]
[/code]
Last edited on
When posting code, please enclose it in code tags to make it easier to read.
Sorry for this mistake and was amended I am waiting for your help me
I personally think your program is way too complicated and horrible to read.

Here is the perfectly working code of yours (which included iostream.h, what a laugh) with indentation:

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
119
#include<iostream>
#include<string.h>

using namespace std;

int room[10],price;
int top;

struct hotel{
	int bed;
	char firstname[30],lastname[30];
	hotel *next;
};

typedef struct hotel *ptr;
typedef ptr list;

hotel *push(list h,char fn[30],char ln[30],int b)
{
	hotel *temp;

	if(h==NULL)
	{
		h=new hotel;
		strcpy(h->firstname,fn);
		strcpy(h->lastname,ln);
		h->bed=b;
		h->next=NULL;
	}
	else
	{
		temp=new hotel;
		strcpy(temp->firstname,fn);
		strcpy(temp->lastname,ln);
		temp->bed=b;
		temp->next=h;
		h=temp;
	}
	return h;
}

void push1(int r)
{
	if(top==10)
	{
		cout<<"error:stack overflow \n";
	}
	else
	{
		top++; room[top]=r;
	}
}

void print(list h,int b)
{
	hotel *temp=h;

	while(temp!=NULL)
	{cout<<"name is:"<<temp->firstname<<"\t"<<temp->lastname<<endl;

	if(b==1)
	{
		cout<<"price is: 1000$"<<endl;
	}

	if(b==2)
	{
		cout<<"price is: 1500$"<<endl;
	}

	temp=temp->next;}
}

int pop1()
{
	if (pop1<0)
	{
		cout<<"error:stack underflow \n";
	}
	else
	{
		return room[top--];
	}
}

hotel *pop(list h)
{
	hotel *temp;
	temp=h;
	h=temp->next;
	delete temp;
	return h;
}

void main()
{
	int b;
	char fn[30],ln[30];

	top=-1;

	list head=NULL;

	cout<<"enter your full name:";
	cin>>fn>>ln;

	cout<<"enterthe number of bed 1 or 2:";
	cin>>b;

	head=push(head,fn,ln,b);

	print(head,b);
	push1(1);

	cout<<"room is:";
	cout<<pop1();

	head=pop(head);
}


I think you have just taken the code from someone else, cuz if you knew so much, you should have already known indentation.

If I have free time tomorrow, I will be happy to finish your program.
(Cuz i am interested to! :) )
Last edited on
Topic archived. No new replies allowed.