Thread: Very simple question

  1. #1
    Registered User
    Join Date
    Dec 2004
    Posts
    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. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    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.
    Hope is the first step on the road to disappointment.

  3. #3
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,218
    I thought a rectangle was a 2D entity. Maybe the problem is you're using 3 dimensions
    If you understand what you're doing, you're not learning anything.

  4. #4
    Registered User
    Join Date
    Dec 2004
    Posts
    73

    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. #5
    ---
    Join Date
    May 2004
    Posts
    1,379
    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. #6
    Registered User
    Join Date
    Mar 2004
    Posts
    536
    Quote 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. #7
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    Non-mathematicians call it a box, or perhaps rectangular box if they must make a point.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Simple question regarding variables
    By Flakster in forum C++ Programming
    Replies: 10
    Last Post: 05-18-2005, 08:10 PM
  2. Simple class question
    By 99atlantic in forum C++ Programming
    Replies: 6
    Last Post: 04-20-2005, 11:41 PM
  3. Simple question about pausing program
    By Noid in forum C Programming
    Replies: 14
    Last Post: 04-02-2005, 09:46 AM
  4. simple question.
    By InvariantLoop in forum Windows Programming
    Replies: 4
    Last Post: 01-31-2005, 12:15 PM
  5. simple fgets question
    By theweirdo in forum C Programming
    Replies: 7
    Last Post: 01-27-2002, 06:58 PM