# Thread: Very simple question

1. ## Very simple question

Code:
```#include <stdio.h>
int main (void) {
int Height;
int Length;
int Width;
printf("What is the height of your rectangle?\n");
scanf("%d",Height);
printf("What is the length of your rectangle?\n");
scanf("%d",Length);
printf("What is the width of your rectangle?\n");
scanf("%d",Width);
printf("The area of your rectangle is %d",Width*Height*Length);
return 0;
}```
Im new to this programming thing and I just can't seem to get this to work..

2. scanf expects pointers as its arguments. As such, for non-pointer variables, you have to give the address of the variable to scanf:
Code:
```int foo;
scanf( "%d", &foo );```
With pointers, you use the pointer directly:
Code:
```int foo, *bar;
bar = &foo; /* make the pointer point to the address of foo */
scanf( "%d", bar );```

Quzah.

3. I thought a rectangle was a 2D entity. Maybe the problem is you're using 3 dimensions

4. ## Here Is The Code

Code:
```#include <stdio.h>
int main (void) {
int Height,Length,Width,Total;
Height = Length = Width = Total = 0;
printf("What is the height of your cube? ");
scanf("%d",&Height);
printf("What is the length of your cube? ");
scanf("%d",&Length);
printf("What is the width  of your cube? ");
scanf("%d",&Width);
Total = (Width*Height*Length);
printf("\nThe area of your cube is %d",Total);
return 0;
}```
He's right. Rectangle is 2D. Cube is 3D so I put that in place of rectangle.

5. and then it would be
Code:
`printf("\nThe volume of your cube is %d",Total);`
instead of
Code:
`printf("\nThe area of your cube is %d",Total);`

6. Originally Posted by sand_man
and then it would be
Code:
`printf("\nThe volume of your cube is %d",Total);`
instead of
Code:
`printf("\nThe area of your cube is %d",Total);`

<pedantic>

A cube has three equal dimensions. When I took geometry, back in the 20th century, I think they called the object that you have in mind a "rectangular parallelepiped". Lazy latter-day don-wanna-sound-like-mathematicians sometimes call this a "cuboid".

</pedantic>

Regards,

Dave

7. Non-mathematicians call it a box, or perhaps rectangular box if they must make a point.

Popular pages Recent additions