include #include #include #include
const double PI = 3.14159;
using namespace std;
int main()
char shape; char c; char t; char r; // input by the user to // choose T(riangle) , C(ircle), or R(ectangle)
double area ; double length, width; // for the rectangle double radius; // for the circle double base, height; // for the triangle
cout << "This program will calculate the area of a " << " circle, a rectangle or a triangle. " << " to calculate a circle area, input C (or c) " << " to calculate a rectangle area, input R (or r)" << " to calculate a triangle area, input T ( or t)" << "
Input C, T, or R: "; cin >> shape; if(shape=="C"c) cout << " Input the radius of the circle: "; cin >> radius; cout << " You have entered " << radius << " as the radius." < cout << fixed << showpoint << setprecision(2); area = PI * pow(radius,2); cout << " The area of the circle is " << area; else if(shape=="T"t) cout << "Input the base and height of the triangle with a space in between: "; cin >> base >> height; cout << " You have entered " << base << " as the base and " << height << " as the height." << endl; area = (1.0/2.0) * base * height; cout << " The area of the triangle is " << area; else if(shape=="R"r) cout << "Input the length and width of the rectangle with a space in between: "; cin >> length >> width; cout << " You have entered " << length << " as the length and " << width << " as the width." << endl; area = length * width; cout << " The area of the rectangle is " << area;
When I run my program and enter the next temper such as "T", it will still show me the results as if I entered "C".
How do I fix this?
|