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"

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include<iostream.h>
#include<conio.h>
#include<math.h>
int main(void)
{
int choices;
int radius, diameter, area;

cout<<"Enter your Choice: "<<endl;
cout<<"1. Radius " <<endl;
cout<<"2. Diameter "<<endl;
cout<<"3. Area "<<endl;

cout<<"Enter number: "<<endl;
cin>>choice;
clrscr();
return 0;
}

//for radius
if(choice==1)
{
float radius;
float diameter;
float area;

cout<<"Input number: "<<endl;
cin>>radius;
cout<<"\n";

diameter=2*radius;
area=3.1416*radius*radius;

//output
cout<<"The Area and Diameter is "<<"\n";
cout<<"\tArea="<<area<<"\n";
cout<<"\tDiameter="<<diameter<<"\n";

clrscr();
return 0;
}


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
17
18
return 0;
}

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

A few other issues.
The standard libraries should be:
1
2
#include <iostream>
#include <cmath> 

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.