I am new to this website and it told me that my post is mostly code. This is not important to my post, it is here just so I can fulfill the post parameters. Looking at the output, how do I change my code so that it doesn't keep looping incorrectly. I have tried everything and I just can't figure out how to make it work. Keep in mind that I am a beginner programmer. I don't know much syntax. How would I make this loop work using the most simplest syntax? I don't know why it loops once correctly, then displays everything before the for loop and then everything in the else block.
#include <iostream>
#include <string>
#include <istream>
#include <stdlib.h>
using namespace std;
int main()
{
char repeat = 'n';
string circle;
string triangle;
string rectangle;
string shape;
long double areaCircle;
long double areaTriangle;
long double areaRectangle;
do
{
cout << "Type the shape you want to find the area for.\n";
cout << "Circle\n";
cout << "Triangle\n";
cout << "Rectangle\n";
getline(cin,shape);
if (shape == "circle")
{
long double r;
cout << "Enter the radius of the circle.\n";
cin >> r;
areaCircle = (3.14)*(r*r);
cout << "The area of the circle is " << areaCircle << endl;
cout << "Enter 'Y' to repeat, 'N' to quit\n";
cin >> repeat;
}
else if (shape == "triangle")
{
long double h, b;
cout << "Enter the base.\n";
cin >> b;
cout << "Enter the height.\n";
cin >> h;
areaTriangle = (b*h) / 2;
cout << "The area of the triangle is " << areaTriangle << endl;
cout << "Enter 'Y' to repeat, 'N' to quit\n";
cin >> repeat;
}
else if (shape == "rectangle")
{
long double l, w;
cout << "Enter the length.\n";
cin >> l;
cout << "Enter the width.\n";
cin >> w;
areaRectangle = l * w;
cout << "The area of the rectangle is " << areaRectangle << endl;
cout << "Enter 'Y' to repeat, 'N' to quit\n";
cin >> repeat;
}
else if (shape !=circle || shape!= triangle || shape != rectangle)
{
cout << shape << "is not a valid shape.\n";
cout << "Enter 'Y' to repeat, 'N' to quit\n";
cin >> repeat;
}
}
while (repeat == 'y');
system("pause");
return 0;
}