Welcome Guest ( Log In | Register )

Outline · [ Standard ] · Linear+

 c++ code downlods

views
     
TSdelsoo
post Dec 10 2016, 01:08 AM

Look at all my stars!!
*******
Senior Member
3,187 posts

Joined: Nov 2013
#include<iostream>
#include<math.h>
int main()
{
char character;
double area;
cout<<"circle©";
cout<<"square(s)";
cout<<"rectangle®";
cout<<"triangle(t)";
cout<<"Select c,s,r or t:";
loop:
cin>>character;
if((character=='c')||(character=='C'))
{
double r;
const double pi=3.142;
cout<<"Enter radius:";
cin>>r;
area=pi*pow(r,2);
}
else if((character=='s')||(character=='S'))
{
double l;
cout<<"Enter length:";
cin>>l;
area=pow(l,2);
}
else if((character=='r')||(character=='R'))
{
double l,w;
cout<<"Enter length:";
cin>>l;
cout<<"Enter width:";
cin>>w;
area=l*w;
}
else if((character=='t')||(character=='T'))
{
double b,h;
cout<<"Enter base:";
cin>>b;
cout<<"Enter height:";
cin>>h;
area=h*b/2;
}
else
{
cout<<"Select only c,s,r or t:";
goto loop;
}
cout<<"Area:"<<area<<endl;

i found this cie , but i am getting these error , what is wrong with the code ?


Attached thumbnail(s)
Attached Image
soulz69
post Dec 10 2016, 03:33 PM

:: LoveHate ::
******
Senior Member
1,651 posts

Joined: Dec 2007
From: Cheat Enabled!



» Click to show Spoiler - click again to hide... «


missing:
1. curly braces
2. using namespace std;

goodluck
Ebony & Ivory
post Dec 10 2016, 06:49 PM

Enthusiast
*****
Senior Member
953 posts

Joined: Jan 2016
QUOTE(delsoo @ Dec 10 2016, 12:55 AM)
yes , when i click c++ code example , there 's also c code come out . I know that because somone in this forum told me that scanf represent c code
*
The only reason C++ has scanf is for compatibility with C. C++ iostreams should be thought of as replacing the C stdio library.

As a rule, use the native features of a language no matter how backwards compatible it is with another one.

Otherwise, you'll be mixing "meaning layers". There's a reason why they are called different languages. As the way C expresses code is totally different to the way real C++ does it. The same reason why people will look at you awkwardly if you happen to use English vocabulary with German syntax is valid here, do not mix C and C++ just because the C++ compiler allows you.

This post has been edited by Ebony & Ivory: Dec 10 2016, 06:53 PM
dstl1128
post Dec 11 2016, 09:00 PM

Look at all my stars!!
*******
Senior Member
4,463 posts

Joined: Jan 2003
What's stopping you from downloading Hello World and do the flow chart?


 

Change to:
| Lo-Fi Version
0.0119sec    0.49    6 queries    GZIP Disabled
Time is now: 29th March 2024 - 04:17 PM