Basically what I am trying to do is get the width and height of the doors in a room. The user enters the number of doors in the room, it then goes into a for loop which then asks for the width and height of each wall.
The problem is I need to work out the area of each door but it just will not work!

Heres my code

``````for (int door = 1; (door < 2); door++)
{
cout << "Enter the width of door" << door << " ";
cin >> doorW[door];
cout << "Enter the height of door" << door << " ";
cin >> doorH[door];

door = door[door] * door[door]; // works ok
cout << "Total area of all doors " << door;

total_door = door[door] + door[door]; // this does not work
}``````

Any ideas? Thanks :)
Any ideas?

3
Contributors
12
Replies
13
Views
9 Years
Discussion Span
Last Post by Phil++

Can you include some variable declarations? Otherwise I can't understand how

``door[door]``

even compiles.

Walls:

``````int wallH[100];
int wallW[100];

int wall[100];
double total_wall;

for (int w=0; (w < total_walls); w++)
{
cout << "Enter the width of door" << w << " ";
cin >> wallW[w];
cout << "Enter the height of door" << w << " ";
cin >> wallH[w];

wall[w] = wallW[w] * wallH[w];
total_wall = wall[w] + wall[w];
}``````

doesn't work

I still don't know where your 'door' variable is coming from, and some specific errors other than "doesn't work" would be much more helpful. Are they compiler errors or does the code just not produce the right output?

It's the walls one above now (sorry) and there are no errors, so for example....

It says: Please enter the width of wall 1: 2
Please enter the height of wall 1: 1

The result should be, 2
and the area should be 3
however, if 5 walls then it will not calculate them... If you see what I mean. It just displays 1

basically, it is missing out 2 calculations

Walls:

``````int wallH[100];
int wallW[100];

int wall[100];
double total_wall;

for (int w=0; (w < total_walls); w++)
{
cout << "Enter the width of door" << w << " ";
cin >> wallW[w];
cout << "Enter the height of door" << w << " ";
cin >> wallH[w];

wall[w] = wallW[w] * wallH[w];
total_wall = wall[w] + wall[w];
}``````

doesn't work

``total_wall = wall[w] + wall[w];``

This line is the same as:

``total_wall = 2 * wall[w];``

Do you want:

``total_wall = total_wall+ wall[w];``

It's the walls one above now (sorry) and there are no errors, so for example....

It says: Please enter the width of wall 1: 2
Please enter the height of wall 1: 1

The result should be, 2
and the area should be 3
however, if 5 walls then it will not calculate them... If you see what I mean. It just displays 1

"Result should be 2 and the area should be 3"? You lost me. 2 times 1 is 2, but where does the 3 come from?

Because you then need to add all the walls together to get the total room if you get what I mean?
So like:
Wall1 + wall2 + wall 3 etc

I want to do that using an array

wall[w] + wall[w];

but the problem is, the user inputs how many walls they have in a room.

Is there any way to add the area of a wall using an array? Thanks

Because you then need to add all the walls together to get the total room if you get what I mean?
So like:
Wall1 + wall2 + wall 3 etc

I want to do that using an array

wall[w] + wall[w];

but the problem is, the user inputs how many walls they have in a room.

Read my last post. The correction I made is what I assume you want.

``total_wall = total_wall + wall[w];``

Make sure you initialize `total_wall` to 0 before going through the loop. If you do, by the end of the loop `total_wall` should equal:

``wall[0] + wall[1] + wall[2] + wall[3] + wall[4]``

if there are 5 walls.

It's weird, it works if i go:

total_wall = wall_area[1] + wall_area[2] + wall_area[3];

the only thing is, I can't do this as the user enters the number of windows :(

So they could enter 5, any ideas?

It's weird, it works if i go:

total_wall = wall_area[1] + wall_area[2] + wall_area[3];

the only thing is, I can't do this as the user enters the number of windows :(

So they could enter 5, any ideas?