Guest User

Untitled

a guest
Mar 31st, 2012
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. // Volume.cpp : Defines the entry point for the console application.
  2. //
  3. #include "stdafx.h"
  4. #include <stdio.h>
  5. #include <math.h>
  6. double cylinder( double d )
  7. {
  8. double pi = 3.14159;
  9. return pi * (pow (d,3))/4;
  10. }
  11. double cube( double s )
  12. {
  13. return pow (s,3);
  14. }
  15. double sphere( double d )
  16. {
  17. double pi = 3.14159;
  18. return (4/3) * pi * (pow (d,3))/8;
  19. }
  20. int main( )
  21. {
  22. double d;
  23. double s;
  24. char menu_char;
  25. puts( "---Volume Calculation Program---" );
  26. printf( "Which option would you like to use?\n" );
  27. printf( "A Cylinder\nB Cube\nC Sphere\nQ Quit\n\n" );
  28. menu_char = getchar();
  29. while ( menu_char != 'Q' )
  30. {
  31. if ( menu_char = 'A' )
  32. {
  33. printf( "What is the diameter of the cylinder?\n" );
  34. scanf( "%g", &d );
  35. cylinder( d );
  36. }
  37. else
  38. if ( menu_char = 'B' )
  39. {
  40. printf( "What is the side of the cube?\n" );
  41. scanf( "%g", &s );
  42. cube ( s );
  43. }
  44. else
  45. if ( menu_char = 'C' )
  46. {
  47. printf ( "What is the diameter of the sphere?\n" );
  48. scanf( "%g", &d );
  49. sphere ( d );
  50. }
  51. else
  52. {
  53. return 0;
  54. }
  55. menu_char = getchar();
  56. }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment