#include <iostream>
#include <string>
using namespace std;
int number_of_sides;
string find_area(int length, int height) {
int area;
string area_message = "The area of your shape is ";
if(number_of_sides == 3){
area = length * height / 2;
area_message += to_string(area);
}
else if(number_of_sides == 4){
area = length * height;
area_message += to_string(area);
}
else{
area_message = "Cannot determine area.";
}
return area_message;
}
int main() {
int height;
int length;
cout << "Give the dimensions of a triangle or parallelogram to find its area.\n";
cout << "What is the length of your shape? ";
cin >> length;
cout << "What is the height of your shape? ";
cin >> height;
cout << "How many sides does your shape have? ";
cin >> number_of_sides; // Use the global variable
cout << find_area(length, height);
return 0;
}
To embed this project on your website, copy the following code and paste it into your website's HTML: