fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5. char shape;
  6. double area;
  7.  
  8. cout << "Select the type of shape:\n";
  9. cout << " t - right triangle\n";
  10. cout << " k - square\n";
  11. cout << " p - rectangle\n";
  12. cout << "Enter your choice: ";
  13. cin >> shape;
  14.  
  15. if (shape == 't') {
  16. double base, height;
  17. cout << "Enter the base of the triangle:";
  18. cin >> base;
  19. cout << "Enter the height of the triangle:";
  20. cin >> height;
  21. area = 0.5 * base * height;
  22. cout << "\n You selected a RIGHT TRIANGLE.\n";
  23. cout << "Its surface area is:" << area << "\n";
  24. }
  25. else if (shape == 'k') {
  26. double side;
  27. cout << "Enter the side length of the square:";
  28. cin >> side;
  29. area = side * side;
  30. cout << "You selected a SQUARE. \n";
  31. cout << "Its surface area is: " << area << "\n";
  32.  
  33. }
  34. else if (shape == 'p') {
  35. double length, width;
  36. cout << "Enter the length of the rectangle: ";
  37. cin >> length;
  38. cout << "Enter the width of the rectangle: ";
  39. cin >> width;
  40. area = length * width;
  41. cout << "You selected a RECTANGLE. \n";
  42. cout << "Its surface area is: " << area << "\n";
  43. }
  44. else {
  45. cout << "Invalid choice! Please run the program again and select t, k, or p. \n";
  46.  
  47. }
  48. return 0;
  49. }
Success #stdin #stdout 0.01s 5304KB
stdin
Standard input is empty
stdout
Select the type of shape:
 t - right triangle
  k - square
  p - rectangle
Enter your choice: Invalid choice! Please run the program again and select t, k, or p.