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





Post new topic Reply to topic  Page 1 of 1
 [ 2 posts ] 
Author Message
 Post subject: C++ if and else problem?
PostPosted: Wed Jun 04, 2014 11:51 pm 
Offline
User avatar

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: ";
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?


Top
 Profile      
 
 Post subject: C++ if and else problem?
PostPosted: Sun Feb 24, 2019 6:14 pm 
Offline
User avatar

Joined: Thu Apr 02, 2009 11:09 pm
Posts: 1353
Your logical expressions are wrong.

You cannot use
shape==Rr

You must use
shape==R shape == r



Top
 Profile      
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  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:  

cron
Click me:
Powered by phpBB © 2000, 2002, 2005, 2007, 2008, 2009 phpBB Group
Chronicles phpBB3 theme by Jakob Persson. Stone textures by Patty Herford.
With special thanks to RuneVillage

This site have 4 type of tecnology in order to convert text to speech. By default you use the vozme tecnology. In order to know the other you need to sign for.


- Privacy Policy -