this code keep crashing while no compiler errors

This code keep crashing while compiler gives no error!

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
#include<iostream>
#include<string>
namespace std;

class space
{
	public:
		
		void Set_spa_na(string sp_na){space_name = sp_na;}
		string Get_spa_na(){return space_name;}
	
		void Set_height(float h){height = h;}
		float Get_height(){return height;}
		
		void Set_size(float s){size = s;}
		float Get_size(){return size;}
		
		void Set_cond(bool c){conditioned = c;}
		bool Get_cond(){return conditioned;}
		
		void Set_st_no(int St_No){store_no = St_No;}
		int Get_st_no(){return store_no;}
		
		void Set_wl_no(int wl_no){walls_no=wl_no;}
		int Get_wl_no(){return walls_no;}
		
	private:
		string space_name;
		float height;
		float size;
		bool conditioned;
		int store_no;
		int walls_no;
};

class building
{
	public:
		building(int iStoNo,int iSpaNo)
		{
			StoNo = iStoNo;
			SpaNo = iSpaNo;
			SpaceGroup[StoNo,SpaNo];
			for (int j = 0;j<StoNo;j++)
			{
				for (int i=0; i<SpaNo;i++)
				{
				string name="";
				float height =0;
				float size =0;
				char ans= 0;
				int wallno=0;
				SpaceGroup[j,i].Set_st_no(j);
				cout<<endl<<"Enter Space "<<i+1<<" in floor "<<j+1<<" name: "<<endl;
				cin>>name;
				SpaceGroup[j,i].Set_spa_na(name);
				cout<<endl<<"Enter space "<<i+1<<" in floor "<<j+1<<" height: "<<endl;
				cin>>height;
				SpaceGroup[j,i].Set_height(height);
				cout<<endl<<"Enter space "<<i+1<<" in floor "<<j+1<<" Size(Area): "<<endl;
				cin>>size;
				SpaceGroup[j,i].Set_size(size);
				cout<<endl<<"Is the space "<<i+1<<" in floor "<<j+1<<" Conditioned? [Y/N]"<<endl;
				cin>>ans;
				if (ans =='Y'){SpaceGroup[j,i].Set_cond(true);}
				else {SpaceGroup[j,i].Set_cond(false);}
				cout<<endl<<"Enter space "<<i+1<<" in floor "<<j+1<<" number of walls: "<<endl;
				cin>>wallno;
				SpaceGroup[j,i].Set_wl_no(wallno);
				}
				
			}
		}
		
		space Get_space_info(int j,int i)
		{
		return SpaceGroup[j,i]	;
		}
			
	private:
		int StoNo;
		int SpaNo;
		space SpaceGroup[];

};

int main()
{
	int Story_No;
	int Space_No;
	cout<<"Enter number of stoies: "<<endl;
	cin>>Story_No;
	cout<<"Enter number of spaces in each story: "<<endl;
	cin>>Space_No;
	building New_building(Story_No,Space_No);
	cout<<endl<<endl<<"***Displaying Entered Data***"<<endl<<endl;
	
	for(int j=0;j<Story_No;j++)
	{
		for(int i=0;i<Space_No;i++)
		{
		cout<<endl<<"The name of space "<<i+1<<" in story number "<<j+1<<" is: "<<New_building.Get_space_info(j,i).Get_spa_na()<<endl;
		cout<<endl<<"The hieght of space "<<i+1<<" in story number "<<j+1<<" is: "<<New_building.Get_space_info(j,i).Get_height()<<" m."<<endl;	
		cout<<endl<<"The Size(Area) of space "<<i+1<<" in story number "<<j+1<<" is: "<<New_building.Get_space_info(j,i).Get_size()<<" m2."<<endl;
		cout<<endl<<"The  space "<<i+1<<" in story number "<<j+1<<" have "<<New_building.Get_space_info(j,i).Get_wl_no()<<" wall(s)"<<endl;
		if(New_building.Get_space_info(j,i).Get_cond()==true)
			{
			cout<<endl<<"The space "<<i+1<<" in story number "<<j+1<<" is conditioned."<<endl;
			}
		else {cout<<endl<<"The space "<<i+1<<" in story number "<<j+1<<" is (not) conditioned."<<endl;}
		
		}
	}
	return 0;
}
Last edited on
closed account (48T7M4Gy)
line 3 using namespace std;

Also you are declaring a dynamic 2d array incorrectly by the look of it. Also a 2d array is array[x][y] not array[x,y]

https://stackoverflow.com/questions/936687/how-do-i-declare-a-2d-array-in-c-using-new

Last edited on
Gives no error? An another does stop on error and warns a lot too:
3:14: error: expected '{' before ';' token
3:14: warning: extra ';' [-Wpedantic]
83:20: warning: ISO C++ forbids zero-size array 'SpaceGroup' [-Wpedantic]
  In constructor 'std::building::building(int, int)':
43:21: warning: left operand of comma operator has no effect [-Wunused-value]
43:26: warning: statement has no effect [-Wunused-value]
53:18: warning: left operand of comma operator has no effect [-Wunused-value]
56:18: warning: left operand of comma operator has no effect [-Wunused-value]
59:18: warning: left operand of comma operator has no effect [-Wunused-value]
62:18: warning: left operand of comma operator has no effect [-Wunused-value]
65:33: warning: left operand of comma operator has no effect [-Wunused-value]
66:24: warning: left operand of comma operator has no effect [-Wunused-value]
69:18: warning: left operand of comma operator has no effect [-Wunused-value]
  In member function 'std::space std::building::Get_space_info(int, int)':
77:23: warning: left operand of comma operator has no effect [-Wunused-value]
  At global scope:
115:1: error: expected '}' at end of input


Increase the verbosity of your compiler.
My compiler gives two errors.

Line 83:
 
		space SpaceGroup[];

[Error] ISO C++ forbids zero-size array 'SpaceGroup' [-Wpedantic]


In addition there are several compiler warnings, which are as already stated due to the incorrect use of the 2D array.
thanks I will try and see if it works with me
Topic archived. No new replies allowed.