### Computing Radius, Area and Diameter program

Im tying to create a program that could either area, diameter or radius (depends on what the user will pick) then it will compute 2 outputs.

example, i pick radius the output will be in diameter and area.
im really a beginner and i got the message "Delaration terminated incorrectly"

 ``123456789101112131415161718192021222324252627282930313233343536373839404142`` ``````#include #include #include int main(void) { int choices; int radius, diameter, area; cout<<"Enter your Choice: "<>choice; clrscr(); return 0; } //for radius if(choice==1) { float radius; float diameter; float area; cout<<"Input number: "<>radius; cout<<"\n"; diameter=2*radius; area=3.1416*radius*radius; //output cout<<"The Area and Diameter is "<<"\n"; cout<<"\tArea="<

well, this is not yet finished, just planning to finish first the radius since if i got this, it will be easy for the rest.

could any of you guys help me and can also check "ALL" the wrong things i did in coding?

it will really be appreciated.
Try to use the switch statements, it is much easier.

PS: I'm a beginner, so I don't know what does that error "really" means
Last edited on
There are two obvious errors, and a few other issues too.
One, a variable called `choices` is declared, and later `choice` is referred to. Note the difference in spelling, it needs to be the same in both cases.

The other issue is, main() ends with the closing brace '}' at line 18.
Then after that, there is some additional code which isn't part of main, or any other function.

So, move lines 17 and 18
 ``1718`` ``````return 0; }``````

and put them right at the end, after line 41.

A few other issues.
The standard libraries should be:
 ``12`` ``````#include #include ``````

without the .h suffix. Note that when you do this, you will need to do something like `using namespace std;` at the top of the program, before the start of main(), or use the prefix `std::` for names like `std::cin` and `std::endl`

Back to the code. You defined at line 7 `int radius, diameter, area;`
and then later defined them again as type float at line 23. In this case the compiler will accept this, but it is pointless, as one set of variables hide the others. Also it is better to define pi just once as a constant, rather than typing its value directly into each expression.
` const double pi = 3.1415926535897932385;`
Note, I would recommend the use of `double` rather than `float` as a matter of routine, because of its higher precision.

As well as that, there is the use of `clrscr()` which is non-standard, but more to the point, at line 39 it will mean your output is cleared before you get a chance to read it.
Last edited on
Topic archived. No new replies allowed.