Advertisement
Spocoman

07. Area of Figures

Sep 1st, 2023 (edited)
735
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.76 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main() {
  6.     string figure;
  7.     cin >> figure;
  8.  
  9.     double area = 0;
  10.  
  11.     if (figure == "square") {
  12.         double side;
  13.         cin >> side;
  14.  
  15.         area = side * side;
  16.     }
  17.     else if (figure == "rectangle") {
  18.         double length, width;    
  19.         cin >> length >> width;
  20.  
  21.         area = length * width;
  22.     }
  23.     else if (figure == "circle") {
  24.         double radius;
  25.         cin >> radius;
  26.  
  27.         area = 3.14159265359 * radius * radius;
  28.     }
  29.     else if (figure == "triangle") {
  30.         double base, height;
  31.         cin >> base >> height;
  32.  
  33.         area = base * height / 2;
  34.     }
  35.  
  36.     cout.setf(ios::fixed);
  37.     cout.precision(3);
  38.    
  39.     cout << area << endl;
  40.    
  41.     return 0;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement