i'm writing a program that allows the user to choose to find the area of three different geometric shapes by inputting a letter, but i can't figure out what's wrong in the code thats not making the program actually choose one when its run:
// Geometry
// Calculates area of a circle, triangle or rectangle
#include <cmath>
#include <iostream>
#include <iomanip>
#include <string>
constdouble PI = 3.14159;
usingnamespace std;
int main()
{
char shape; // 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 "
<< "\ncircle, a rectangle or a triangle.\n"
<< " \nto calculate a circle area, input C (or c) "
<< " \nto calculate a rectangle area, input R (or r )"
<< " \nto calculate a triangle area, input T ( or t)"
<< " \n\nInput C, T, or R ";
cin >> shape;
cout << endl;
if (shape == 'C'||'c')
{
cout << "Input The Radius Of The Circle: " << endl;
cin >> radius;
cout << endl;
area = PI * pow(radius, 2);
cout << area << endl << endl;
}
if (shape == 'R'||'r')
{
cout << "Input The Length Of The Rectangle: " << endl << endl;
cin >> length;
cout << "Input The Width Of The Rectangle: " << endl << endl;
cin >> width;
area = length * width;
cout << area << endl << endl;
}
if (shape == 'T'||'t')
{
cout << "Input The Base Of The Triangle: " << endl << endl;
cin >> base;
cout << "Input The Height Of The Triangle: " << endl << endl;
cin >> height;
area = .5 * base * height;
cout << area << endl << endl;
}
if (shape == !'T'|!'t'|!'C'|!'c'|!'R'|!'r')
cout << "Invalid Response Is Invalid." << endl << endl;
system("pause");
return 0;
}
ohhh, okay, thanks, i thought it might be a problem with the if's, and for the last one, it's supposed to basically output that the user typed an invalid character, i.e. not C,R, or T, so should i make that if similar to the other ones, or can I just use an 'else' statement?
aha! thanks so much! i was wondering why the code would run, but it would still cout invalid response even if it chose the right option and everything, thanks for the help!