Advertisement
Guest User

Untitled

a guest
Sep 21st, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.88 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4. //This is prototyping the functions for later when the if statement calls for a function.
  5. int triangle();
  6. int circle();
  7. int square();
  8.  
  9. int main()
  10. {
  11. cout << "Welcome to my area calculator,\n please select a shape using the numbers as a selection.\n\n" << "1.Triangle\n2.Circle\n3.Square\n";
  12. int selection;
  13. cin >> selection;
  14. cout << endl;
  15.  
  16.  
  17. if (selection == 2){
  18. circle();
  19. }
  20.  
  21. if (selection>3){ //This if statement checks if the selection is valid or not, currently works for numbers but not text.
  22.  
  23. cout << "Sorry that wasn't one of the options.";
  24.  
  25. main();
  26. }
  27.  
  28. //the if statements below check which shape was selected to begin the calculation.
  29. if(selection == 1){
  30. triangle();
  31. }
  32.  
  33. if (selection == 2){
  34. circle();
  35. }
  36.  
  37. if (selection == 3){
  38. square();
  39. }
  40.  
  41. return 0;
  42. }
  43.  
  44. //Below are the functions for each calculations
  45. int triangle(){
  46.  
  47. int base;
  48. int height;
  49. cout << "Please enter the base length of your triangle : ";
  50. cin >> base;
  51. cout << " \n\nPlease enter the Height of your triangle : ";
  52. cin >> height;
  53. cout << "The area of the triangle is : ";
  54.  
  55. int triangle;
  56. triangle = (height + base) / 2;
  57.  
  58. cout << triangle;
  59.  
  60. return triangle;
  61.  
  62.  
  63. }
  64.  
  65. int circle(){
  66. int radius;
  67. cout << "Please enter the radius of the circle : ";
  68. cin >> radius;
  69. cout << "\n\nThe area of the circle is : ";
  70.  
  71. double circle;
  72. circle = 3.14 * radius * radius;
  73. cout << circle;
  74.  
  75. return circle;
  76.  
  77. }
  78.  
  79.  
  80. int square(){
  81.  
  82. double width;
  83. double height;
  84. cout << "Please enter the height of your square : ";
  85. cin >> height;
  86.  
  87. cout << "\n\nPlease enter the width of your square : ";
  88. cin >> width;
  89.  
  90. int square;
  91. square = width * height;
  92. cout << "\n\nThe area of the square is : " << square;
  93.  
  94. return square;
  95.  
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement