cout << "You need to find the area of a square, a rectangle, a trapezoid, a parallelogram, or a triangle? ";
cin >> shape;
if(shape=="square"){
cout << "Enter the length of one side: ";
cin >> side;
answ = side * side;
cout << "The area of the square is: " << answ;
}
if(shape=="rectangle"){
cout << "Enter the base: ";
cin >> base;
cout << "Enter the height: ";
cin >> height;
answ = base * height;
cout << "The area of the rectangle is " << answ;
}
if(shape=="trapezoid"){
cout << "Enter base one: ";
cin >> base1;
cout << "Enter base two: ";
cin >> base2;
cout << "Enter the height: ";
cin >> height;
answ = .5 * (base1+base2) * height;
cout << "The area of the trapezoid is " << answ;
}
if(shape=="parallelogram"){
cout << "Enter the base: ";
cin >> base;
cout << "Enter the height: ";
cin >> height;
answ = base * height;
cout << "The area of your parallelogram is " << answ;
}
if(shape=="triangle"){
cout << "Enter the base: ";
cin >> base;
cout << "Enter the height: ";
cin >> height;
answ = .5*(base*height);
cout << "The area of your triangle is " << answ;
}
I want to make it so if the shape isn't either of the ones I programmed, or just random text, that it will print something similar to "Invalid input"
if (shape == "square")
{
//Do calculations here
}
elseif (shape == "rectangle")
{
//Do calcs here
}
//..... Do else if statements for all shapes you want to include in your program
//finally:
else
{
cout << "Invalid input" << endl;
}