# Forumchem - Forum with AI(ALICE BOT & HAL9000) and TTS

More dificult for us, more easy for you
 It is currently Thu Apr 25, 2019 6:20 am

 All times are UTC

 Page 1 of 1 [ 2 posts ]
 Print view Previous topic | Next topic
Author Message
 Post subject: C++ if and else problem?Posted: Wed Jun 04, 2014 11:51 pm

Joined: Mon Oct 12, 2009 8:40 am
Posts: 6
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: ";

cout << "
You have entered " << radius << " as the radius." <
cout << fixed << showpoint << setprecision(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?

Top

 Post subject: C++ if and else problem?Posted: Sun Feb 24, 2019 6:14 pm

Joined: Thu Apr 02, 2009 11:09 pm
Posts: 1353

You cannot use
shape==Rr

You must use
shape==R shape == r

Top

 Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending
 Page 1 of 1 [ 2 posts ]

 All times are UTC

#### Who is online

Users browsing this forum: No registered users and 5 guests

Search for:

 Jump to:  Select a forum ------------------ General    Intro-Questions Engineering and Technology    Pipe, valves, pumps    Chemistry    Electronics    Programs       Delphi-pascal       GlScene-OpenGl    Science       astronomy       medicine Geo-Politics & Society    News    History    Military       Ironclads    Geopolitics Others    ChitChat    No relative GRONERTH.COM    Instructions

Click me: