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 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
|
#include "stdafx.h"
#include <iostream>
#include <cmath>
#include <string>
using namespace std;
//Prototype
double cylvol(double, double);
double surfarea(double, double);
int main()
{
double V = 0, S = 0;
double r1, L1, r2, L2;
char option;
cout << "Do you want to calculate the volume or the side surface of a cylinder? \n";
cout << "Press 1 for volume.\n";
cout << "Press 2 for side surface.\n";
cout << "Press 3 to exit.\n";
cin >> option;
if (option == '1')
{
cout << "Ok, you want to calculate the volume.\n";
cout << "Please enter a radius. ";
cin >> r1;
cout << "Now, enter a length. ";
cin >> L1;
V = cylvol(r1, L1);
cout << "The Volume of your cylinder is: " << V << endl;
}
if (option == '2')
{
cout << "Ok, you want to calculate the side surface.\n";
cout << "Please enter a radius. ";
cin >> r2;
cout << "Now, enter a length. ";
cin >> L2;
S = surfarea(r2, L2);
cout << "The Surface Area of your cylinder is: " << S << endl;
}
if (option == '3')
cout << "Goodbye! ";
system("pause");
return 0;
}
double cylvol(double r1, double L1)
{
double V;
const double pi = 3.14
V = ((pi) * (pow(r1, 2)) * (L1));
return V;
}
double surfarea(double r2, double L2)
{
double S;
const double pi = 3.14
S = ((2) * (pi) * (r2) * (L2));
return S;
}
|