# Thread: Intro to C++, NEED HELP!!!

1. ## Intro to C++, NEED HELP!!!

I have to write a program to calculate the diameter, the circumference, and the area of a circle with a radius of 6.75. Please tell me what I am doing wrong...I am going on 5 hours, and I am lost:-( Any help would be greatly appreciated.

//************************************************
//Calculations of a circle program
//This program finds the diameter, circumference
//and the area of a circle with a preset radius.
//************************************************

#include <iostream>
#include <iomanip>
#include <cmath>

using namespace std;

float pi ;

int main()

{

pi = 3.14159; //Size of PI

cout << "The radius of a circle is : "<< radius << endl;

circumference = diameter * pi;

cout << "The diameter is " << diameter << endl;
cout << "The circumference is " << circumference << endl;
cout << "The area is " << area << endl;

return 0;
}

float pi

forgot the ; ?

3. diameter
circumference
area

u dont declare those

4. that was my bad...I put them in..what do u mean I dont declare them...how do I do that? I thought if I put = something then that is declaring them...I think I am lost.. Thanks

5. To declare a variable, you need to give it a type - i.e.:

double diameter = ...;
float x;
... etc ...

6. try something like

Code:
```

const double PI = 3.14159;

double diameter, circumference, area;

etc.```
you need to declare variables before you use them. radius and PI would make better constants since they are not likely to change.

7. or you can do this...
Code:
```double diameter = 2*radius;
double circumference = diameter * pi;

8. I put the following:
const doble PI = 3.14159;

and

double diameter, double circumference, double area and sure enough it worked. Thanks for the help.

I read Chapter 3 over again today and I dont know why I needed to add double in front of those to make it work...could someone explain that to me, I would really appreciate it alot.

Bryan

9. C++ is a strongly typed language. It makes sure everything has a type, type promotion rules are followed closely (i.e. the result of int+double=double), and no type is used in an improper way.

As a result of all of this, it needs to know the type of a variable when you create it.

10. I know you are probably repaeting yourself, but what does "double" do for the variable? thanks

Bryan

11. 'double' is a data type. It lets the compiler know that that variable will be storing a value to be represented in a specific way. 'double' can hold floating-point numbers (ones with decimals), as can 'float' s (though a float is smaller).

12. double is a type of variable that can store decimals.... and larger/smaller numbers that float can (not sure exactly how many)

13. so anytime I want to store decimals I should put const double in front it the variable...I think I am getting it. I am taking this onlline at UMUC and its very hard doing this online because there is not much help. I appreciate all you guys that gave me help, I hope you can continue to help me throughout the semester:-)

Bryan

14. Actually, the 'const' modifier just means that its a constant, which cannot be changed in the program. If you want to manipulate the decimal, just use 'double'.

Cheers

15. yeah, the const means that the variable cannot be changed anytime in the program after you declare it. For example:
Code:
```#include <iostream>
using namespace std;
int main()
{
int a=5;
const int b=3;   //Declares a constant integer
cout << a << endl;
cout << n << endl;
a=7;                 //no problem, this one isnt const
b=4;                //Will get an error for trying to change the  value of a constant
cout << a << endl;
cout << b << endl; //erase the const infront of int b and it will compile to see that both a and b can change :D
return 0;
}```