PDA

View Full Version : volume of a rectangular prism




sg001
Aug 1, 2012, 06:14 AM
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..



// 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

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.



robbieduncan
Aug 1, 2012, 06:38 AM
You can't have spaces in variable names

whooleytoo
Aug 1, 2012, 06:38 AM
"surface area". You can't have a space in a variable name. Same with "edge length".

Try "surfaceArea", "edgeLength" instead.

sg001
Aug 1, 2012, 07:10 AM
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:)

robbieduncan
Aug 1, 2012, 07:11 AM
Are you typing something like:

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

or

1 2 3<return>
?