Help with some beginner C code!

Member
Posts: 51
Joined: 2005.07
Post: #46
well, i finished everything, except i still can't figure out the problem with the cube skipping input lines and the circle not repeating.

Code:
#include <stdio.h>

int main()
{

    int area;
    int radius;
    int length;
    int depth;
    int width;
    int height;
    int side;
    int pi = 3.14;
    int shape;
    int repeat = 0;
    
        do {
    
        printf( "\nWhat shape would you like to find the area of?\n" );
        printf( "Enter 1 for circle.\n" );
        printf( "Enter 2 for square.\n" );
        printf( "Enter 3 for cube.\n" );
        printf( "Enter 4 for cylinder.\n" );
        printf( "Enter 5 for parallelogram.\n\n" );
        scanf( "%d" , &shape );
    
        switch (shape) {
            case 1:
                printf( "\nEnter the radius of the circle:  \n" );
                scanf( "%d" , &radius );
            
                area = pi * radius * radius;
                printf( "\nThe area of the circle is %d.\n" , area );
                    break;
            case 2:
                printf( "Enter the length of one side of the square:  \n" );
                scanf( "%d" , &side );
                
                area = side * side;
                printf( "The area of the square is %d.\n" , area );
                    break;
                    
            case 3:
                printf( "\nEnter the height of the cube:  \n" );
                scanf( "%d" , &height );
                
                printf( "Enter the width of the cube:  \n" );
                scanf( "%d" , &width );
                
                printf( "Enter the depth of the cube:  \n" );
                scanf( "%d" , &depth );
                
                area = height * width * depth;
                printf( "The area of the cube is %d.\n" , area );
                    break;
                    
            case 4:
                printf( "Enter the height of the cylinder:  \n" );
                scanf( "%d" , &height );
                
                printf( "Enter the radius of the cylinder:  \n" );
                scanf( "%d" , &radius );
                
                area = 2 * pi * radius * radius + 2 * pi * radius * height;
                printf( "The area of the cylinder is %d." , area );
                    break;
                    
            case 5:
                printf( "Enter the height of the parallelogram:  \n" );
                scanf( "%d" , &height );
                
                printf( "Enter the width of the parallelogram:  \n" );
                scanf( "%d" , &width );
                
                area = length * width;
                printf( "The area of the parallelogram is %d." , area );
                    break;
                
            default:
                repeat = 1;
                
            }
        } while (repeat == 1);
return 0;
}
Quote this message in a reply
Post Reply