1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
|
#include <stdio.h>
#include "simpio.h"
#include "strlib.h"
#include "random.h"
#include <string>
#define PI 3.1415926 // this allows it to be used throughout the code via the preprocessor.
std::string shape;
int main()
{
int i, cube, box, b1, pi, cylinder, s, s2, height;
printf ("Please enter the shape:");
shape=GetLine();
//pi=3.1415167; // moved to preprocessor, commented out.
if (shape=="cube")
{
printf ("Please enter the side: ");
s=GetInteger();
b1=s*s*s;
printf("The volume of a cube with side=%d, is %d.", s, b1);
}
else if (shape=="cylinder")
{
printf ("Please enter the height:");
height=GetInteger();
printf ("Please enter the radius: ");
s=GetInteger();
b1= PI*height*s*s;// capitalize the pi because I capitalized in preprocessor.
printf("The volume of a cylinder with radius=%d and height=%d, is %d.", s, height, b1);
}
else if (shape=="box")
{
printf("Please enter side1:");
s=GetInteger();
printf("Please enter side2:");
s2= GetInteger();
printf ("Please enter the height:");
height=GetInteger();
b1= s*s2*height;
printf ("The volume of a box with sides %d and %d and height of %d is %d.", s, s2, height, b1);
}
return 0;
}
| |