Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <cstdlib>
- #include <cmath>
- using namespace std;
- int main()
- {
- system("CLS"); //Flush the stream
- int loop = 1;
- int choice;
- string getinput;
- bool done = false;
- while (loop ==1)
- {
- system("CLS"); //Flush the stream
- cout << "--Menu--" << endl << endl;
- cout << "1. Cube" << endl;
- cout << "2. Rectengular Prism" << endl;
- cout << "3. Sphere" << endl;
- cout << "4. Cylinder" << endl;
- cout << "5. Cone" << endl;
- cout << "6. Quit" << endl; // menu
- cin >> choice;
- if(choice < 0 || choice > 7)
- cout << "Between 1~6 please." << endl; // between 1~6
- system("pause");
- switch(choice)
- {
- case 1:// Cube
- {
- system("CLS");
- double Cube_Length = 0.0;
- cout << "One side length? " << endl;
- cin >> Cube_Length;
- while(Cube_Length <= 0) {
- cout << "Cannot be negative, Try again: ";
- cin >> Cube_Length;
- }
- cout << "Surface area: " << (Cube_Length*Cube_Length)*6 << endl; // calculates surface ares
- cout << "Volume: " << Cube_Length*Cube_Length*Cube_Length << endl;
- system("pause");
- break;
- }
- case 2://Rectangular
- {
- system("CLS");
- double RP_Length = 0.0, RP_Width = 0.0, RP_Height = 0.0;
- cout << "length? " << endl;
- cin >> RP_Length;
- while(RP_Length <= 0) {
- cout << "Cannot be negative, Try again: ";
- cin >> RP_Length;
- }
- cout << "Width? " << endl;
- cin >> RP_Width;
- while(RP_Width <= 0) {
- cout << "Cannot be negative, Try again: ";
- cin >> RP_Width;
- }
- cout << "Height? " << endl;
- cin >> RP_Height;
- while(RP_Height <= 0) {
- cout << "Cannot be negative, Try again: ";
- cin >> RP_Height;
- }
- cout << "Surface area: " << ((RP_Length*RP_Width)*2)+((RP_Width*RP_Height)*2)+((RP_Length*RP_Height)*2) << endl;
- cout << "Volume: " << RP_Length*RP_Width*RP_Height << endl;
- system("pause");
- break;
- }
- case 3: //Sphere
- {
- system("CLS");
- double Sph_radius = 0.0;
- cout << "Radius? " << endl;
- cin >> Sph_radius;
- while(Sph_radius <= 0) {
- cout << "Cannot be negative, Try again: ";
- cin >> Sph_radius;
- }
- cout << "Surface area: " << 4*M_PI*pow(Sph_radius, 2) << endl;
- cout << "Volume: " << (4*M_PI*pow(Sph_radius, 3))/3 << endl;
- system("pause");
- break;
- }
- case 4://Cylinder
- {
- system("CLS");
- double Cylin_radius = 0.0, Cylin_height = 0.0;
- cout << "Radius? " << endl;
- cin >> Cylin_radius;
- while(Cylin_radius <= 0) {
- cout << "Cannot be negative, Try again: ";
- cin >> Cylin_radius;
- }
- cout << "Height? " << endl;
- cin >> Cylin_height;
- while(Cylin_height <= 0) {
- cout << "Cannot be negative, Try again: ";
- cin >> Cylin_height;
- }
- cout << "Surface area: " << (2*M_PI*pow(Cylin_radius, 2)) + (2*M_PI*Cylin_radius*Cylin_height) << endl;
- cout << "Volume: " << M_PI*Cylin_height*pow(Cylin_radius, 2) << endl;
- system("pause");
- break;
- }
- case 5://Cone
- {
- system("CLS");
- double Cone_radius = 0.0, Cone_height = 0.0;
- cout << "Radius? " << endl;
- cin >> Cone_radius;
- while(Cone_radius <= 0) {
- cout << "Cannot be negative, Try again: ";
- cin >> Cone_radius;
- }
- cout << "Height? " << endl;
- cin >> Cone_height;
- while(Cone_height <= 0) {
- cout << "Cannot be negative, Try again: ";
- cin >> Cone_height;
- }
- cout << "Surface area: " << M_PI*Cone_radius*sqrt(pow(Cone_radius, 2)+pow(Cone_height, 2)) << endl;
- cout << "Volume: " << (M_PI*pow(Cone_radius, 2)*Cone_height)/3 << endl;
- system("pause");
- break;
- }
- case 6: //Quit, couldn't find any method, other than exit(0);
- {
- if(choice==6)
- {
- cout << "Thank you for using the program and See you later!";
- exit(0);
- }
- }
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment