Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Volume.cpp : Defines the entry point for the console application.
- //
- #include "stdafx.h"
- #include <stdio.h>
- #include <math.h>
- double cylinder( double d )
- {
- double pi = 3.14159;
- return pi * (pow (d,3))/4;
- }
- double cube( double s )
- {
- return pow (s,3);
- }
- double sphere( double d )
- {
- double pi = 3.14159;
- return (4/3) * pi * (pow (d,3))/8;
- }
- int main( )
- {
- double d;
- double s;
- char menu_char;
- puts( "---Volume Calculation Program---" );
- printf( "Which option would you like to use?\n" );
- printf( "A Cylinder\nB Cube\nC Sphere\nQ Quit\n\n" );
- menu_char = getchar();
- while ( menu_char != 'Q' )
- {
- if ( menu_char = 'A' )
- {
- printf( "What is the diameter of the cylinder?\n" );
- scanf( "%g", &d );
- cylinder( d );
- }
- else
- if ( menu_char = 'B' )
- {
- printf( "What is the side of the cube?\n" );
- scanf( "%g", &s );
- cube ( s );
- }
- else
- if ( menu_char = 'C' )
- {
- printf ( "What is the diameter of the sphere?\n" );
- scanf( "%g", &d );
- sphere ( d );
- }
- else
- {
- return 0;
- }
- menu_char = getchar();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment