Outline ·
[ Standard ] ·
Linear+
c++ code downlods
TSdelsoo
|
Dec 10 2016, 01:08 AM
|
|
#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)
|
|
|
|
soulz69
|
Dec 10 2016, 03:33 PM
|
|
» Click to show Spoiler - click again to hide... « QUOTE(delsoo @ Dec 10 2016, 01:08 AM) #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 ? missing: 1. curly braces 2. using namespace std; goodluck
|
|
|
|
Ebony & Ivory
|
Dec 10 2016, 06:49 PM
|
|
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
|
Dec 11 2016, 09:00 PM
|
|
What's stopping you from downloading Hello World and do the flow chart?
|
|
|
|