I need help with my functions and probably my ifs. I shouldn't have outputs in my functions but I don't know how to execute that. This program gives the choice of finding the area and perimeter of either a circle, triangle, and rectangle.
#include <iostream>
#include <cmath>
usingnamespace std;
double pi = 3.14;
void areaRectangle()
{
double length;
double width;
cout << "What is your length and width: (Area) " << endl;
cin >> length >> width;
double area = length * width;
cout << "The area of the rectangle is: " << area << endl;
}
void perimeterRectangle()
{
double length;
double width;
cout << "What is your length and width: (Perimeter) " << endl;
cin >> length >> width;
double perimeter = 2 * length + 2 * width;
cout << "The perimeter area of the rectangle is: " << perimeter << endl;
}
void areaTriangle()
{
double base;
double height;
cout << "What is your base and height measurements: (Area) " << endl;
cin >> base >> height;
double area = base * height / 2;
cout << "The area of the triangle is: " << area << endl;
}
//@param: length1 is the first length of the triangle
//@param: length2 is the second length of the triangle
//@param: length3 is the third length of the triangle
void perimeterTriangle()
{
double length1;
double length2;
double length3;
cout << "What is the length of your three sides: (Perimeter) " << endl;
cin >> length1 >> length2 >> length3;
double perimeter = length1 + length2 + length3;
cout << "The perimeter of your triangle is: " << perimeter << endl;
}
void areaCircle()
{
double radius;
cout << "What is your radius: (Area) " << endl;
cin >> radius;
double circumference = 2 * pi * radius;
double area = pi * radius * radius;
cout << "Your circumference is " << circumference << " and your area is " << area << endl;
}
int main()
{
cout << "Which shape do you want to know the area and perimeter of? (circle = 1, rectangle = 2, triangle = 3)" << endl;
int shapeChoice;
cin >> shapeChoice;
if (shapeChoice == 1)
{
areaCircle();
}
elseif (shapeChoice == 2)
{
areaRectangle();
perimeterRectangle();
}
else (shapeChoice == 3);
{
areaTriangle();
perimeterTriangle();
}
return 0;
}