volume of a rectangular prism

Discussion in 'Mac Programming' started by sg001, Aug 1, 2012.

  1. sg001, Aug 1, 2012
    Last edited by a moderator: Aug 1, 2012

    macrumors newbie

    Joined:
    Jul 30, 2012
    #1
    I can't seem to get this code working
    and I don't really know what errors I have made?
    If someone can have a quick look..


    Code:
    // math.c                                                      
    // Author: Samuel Gilbert
    // Date: 31/7/12
    // A simple program computing volume, surface area and total length
    
    #include <stdio.h>
    
    int main(int argc, char * argv[]){
       
       float width, length, height, volume, surface area, edge length
       printf("Enter length: ");
       printf("Enter width: ");
       printf("Enter height: n");
       scanf("%f%f%f", &length, &height, &width);
       volume = (width*length*height);
       printf("volume is %.2f cubic meters\n", volume);
       return 0;
    }
    
    and after compiling heres what I get
    Code:
    math.c: In function ‘main’:
    math.c:10: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘area’
    cc1: warnings being treated as errors
    math.c:14: warning: too many arguments for format
    math.c:14: warning: too many arguments for format
    
    Thanks.
     
  2. Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
  3. macrumors 603

    whooleytoo

    Joined:
    Aug 2, 2002
    Location:
    Cork, Ireland.
    #3
    "surface area". You can't have a space in a variable name. Same with "edge length".

    Try "surfaceArea", "edgeLength" instead.
     
  4. thread starter macrumors newbie

    Joined:
    Jul 30, 2012
    #4
    fixed a little

    ok now I have the program working

    float width, length, height, volume;
    printf("Enter length:\n ");
    printf("Enter height:\n ");
    printf("Enter width: \n");
    scanf("%f %f %f",&length,&height,&width);
    volume = (width*length*height);
    printf("When length is %.2f, ",length);
    printf("When height is %.2f, ",height);
    printf("When width is %.2f, ",width);
    printf("volume is %.2f cubic meters\n",volume);
    return 0;
    }

    Thanks for the help:)
     
  5. Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #5
    Are you typing something like:

    1<return>
    2<return>
    3<return>

    or

    1 2 3<return>
    ?
     

Share This Page