Advertisement
qub1t

switchCase

May 1st, 2022
1,507
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.13 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6.     struct circle
  7.     {
  8.         float radius;
  9.         float diameter;
  10.     };
  11.    
  12.     struct square
  13.     {
  14.         float side;
  15.     };
  16.    
  17.     struct rectangle
  18.     {
  19.         float length;
  20.         float width;
  21.     };
  22.    
  23.     struct triangle
  24.     {
  25.         float base;
  26.         float height;
  27.     };
  28.    
  29.     char choice;
  30.     struct circle circle;
  31.     struct square square;
  32.     struct rectangle rectangle;
  33.     struct triangle triangle;
  34.    
  35.     cin >> choice;
  36.    
  37.     switch(choice)
  38.     {
  39.         case 'C':
  40.             cout << "Enter radius: ";
  41.             cin >> circle.radius;
  42.         cout << 3.14 * (circle.radius * circle.radius) << endl;
  43.             break;
  44.         case 'S':
  45.             cout << "Enter side: ";
  46.             cin >> square.side;
  47.             cout << square.side * square.side;
  48.             break;
  49.         case 'R':
  50.             cout << "Enter length: ";
  51.             cin >> rectangle.length;
  52.             cout << "Enter width: ";
  53.             cin >> rectangle.width;
  54.             cout << rectangle.length * rectangle.width;
  55.             break;
  56.         case 'T':
  57.             cout << "Enter base: ";
  58.             cin >> triangle.base;
  59.             cout << "Enter height: ";
  60.             cin >> triangle.height;
  61.             cout << 0.5 * (triangle.base * triangle.height);
  62.             break;
  63.        
  64.        
  65.     default:
  66.         cout << "Invalid Entry" << endl;
  67.         break;
  68.     }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement