# Im stuck....

• 10-11-2004
dAzed
Im stuck....
I cannot get this program to return any values at all what am I doing wrong please help and thank you for visitng my post...
Code:

``` #include <iostream.h> #include <cmath> double CalculateDist(float, float, float, float);                        //Function prototypes double CalculateRadius(float, float, float, float); double CalculateCircum(double, double); double CalculateArea(double, double); const double Pi = 3.1416; int main() {         float x1 = 0;    // Variables         float x2 = 0;         float y1 = 0;         float y2 = 0;         float dis = 0;         float rad = 0;         float cir = 0;         float are = 0;                         cout << "Please enter the x coordinate for the center point " << endl;         cin >> x1;         cout << "Please enter the y coordinate for the center point " << endl;         cin >> y1;         cout << "Please enter the x coordinate for a point on the circle " << endl;         cin >> x2;         cout << "Please enter the y coordinate for a point on the circle " << endl;         cin >> y2;         cout << "The distance between the points is " << CalculateDist(x1,x2,y1,y2) << endl;         cout << "The radius of the circle is        " << CalculateRadius(x1,x2,y1,y2) << endl;         cout << "The circumfrence of the circle is  " << CalculateCircum(Pi,rad) << endl;         cout << "The area of the circle is          " << CalculateArea(Pi, rad) << endl;                         return 0; } //===================================================================================================================== // Functions double CalculateDist(float x1, float x2, float y1, float y2) {                        return sqrt(pow(x1 - x2, 2) + pow(y1 - y2, 2));         } double CalculateRadius(float x1, float x2, float y1, float y2) {         return        CalculateRadius(x1, x2, y1, y2); } double CalculateCircum(double Pi, double rad) {         return (2* Pi * rad); } double CalculateArea(double Pie, double rad) {         return (Pi * pow(rad, 2)); }```
• 10-11-2004
1) cmath requires you to indicate namespace std somehow. math.h wouldn't, but it isn't standard.

2) You have a never ending recursive function.
• 10-11-2004
dAzed
2) You have a never ending recursive function.

Whats that????

code update still get no values :(

Code:

```#include <iostream> #include <math.h> using namespace std; double CalculateDist(float, float, float, float);                        //Function prototypes double CalculateRadius(float, float, float, float); double CalculateCircum(double, double); double CalculateArea(double, double); const double Pi = 3.1416; double rad = 0; int main() {         float x1 = 0;    // Variables         float x2 = 0;         float y1 = 0;         float y2 = 0;                 cout << "Please enter the x coordinate for the center point " << endl;         cin >> x1;         cout << "Please enter the y coordinate for the center point " << endl;         cin >> y1;         cout << "Please enter the x coordinate for a point on the circle " << endl;         cin >> x2;         cout << "Please enter the y coordinate for a point on the circle " << endl;         cin >> y2;         cout << "The distance between the points is " << CalculateDist(x1,x2,y1,y2) << endl;         cout << "The radius of the circle is        " << CalculateRadius(x1,x2,y1,y2) << endl;         cout << "The circumfrence of the circle is  " << CalculateCircum(Pi,rad) << endl;         cout << "The area of the circle is          " << CalculateArea(Pi, rad) << endl;                         return 0; } //===================================================================================================================== // Functions double CalculateDist(float x1, float x2, float y1, float y2) {                        return sqrt(pow(x1 - x2, 2) + pow(y1 - y2, 2));         } double CalculateRadius(float x1, float x2, float y1, float y2) {         return        CalculateRadius(x1, x2, y1, y2); } double CalculateCircum(double Pi, double rad) {         return (2* Pi * rad); } double CalculateArea(double Pie, double rad) {         return (Pi * pow(rad, 2)); }```
• 10-11-2004
Lithorien
Code:

```double CalculateRadius(float x1, float x2, float y1, float y2) {         return        CalculateRadius(x1, x2, y1, y2); }```
That's recursive. The function calls itself [infinity] times.
• 10-11-2004
misplaced
recursion = funct1(void){ funct1(); }
• 10-11-2004
Epo
Code:

```double CalculateRadius(float x1, float x2, float y1, float y2) {         return        CalculateRadius(x1, x2, y1, y2); }```
A recursive function is a function that keeps on calling itself over and over, as the one above.

In some cases it's useful, but always inside of the function there are safegaurds put in that under certain conditions, the function will skip calling itself again, and return an actual value. (This can never be accomplished, though, if you call the function in the Return, as you've done, hence it's never-ending).

[EDIT]
Guess I was too slow on the trigger
[/EDIT]
• 10-11-2004
try changing this:

to this:

return CalculateDist(x1, x2, y1, y2);
______________________________________
if you use iostream you would logically use cmath and use namespace std. If you use iostream.h you would logically use math.h and not use a namespace.
• 10-11-2004
dAzed
final code
Code:

```#include <iostream> #include <cmath> using namespace std; void getData(float &, float &, float &, float &); double CalcDist(float, float, float, float); double CalcRadius(float, float, float, float); double CalcCircum(double, double); double CalcArea(double, double); void PrintAll(double, double, double, double); int main() {         float x1 = 0;         float x2 = 0;         float y1 = 0;         float y2 = 0;         double distance = 0;         double radius = 0;         double circumfrence = 0;         double area = 0;         const double Pi = 3.1416;         getData(x1, x2, y1, y2);         distance = CalcDist(x1, x2, y1, y2);         radius = CalcRadius(x1, x2, y1, y2);         circumfrence = CalcCircum(Pi, radius);     area = CalcArea(Pi, radius);         PrintAll(distance, radius, circumfrence, area);                 return 0; } void getData(float &xcord1, float &xcord2, float &ycord1, float &ycord2) {         cout << "Please enter the x coordinate for the center point " ;         cin >> xcord1;         cout << "Please enter the y coordinate for the center point " ;         cin >> ycord1;         cout << "Please enter the x coordinate for a point on the circle " ;         cin >> xcord2;         cout << "Please enter the y coordinate for a point on the circle " ;         cin >> ycord2; } double CalcDist(float xcord1, float xcord2, float ycord1, float ycord2) {         return sqrt(pow(xcord1 - xcord2, 2) + pow(ycord1 - ycord2, 2)); } double CalcRadius(float xc1, float xc2, float yc1, float yc2) {         double Temp = 0;         Temp = CalcDist(xc1, xc2, yc1, yc2);         return Temp; } double CalcCircum(double Pie, double rad) {         return (2* Pie * rad); } double CalcArea(double Pie, double rad) {         return (Pie * pow(rad, 2)); } void PrintAll(double dis, double rad, double cir, double are) {         cout << "The distance between the points is :" << dis ;         cout << "The radius of the circle is        :" << rad ;         cout << "The circumfrence of the circle is  :" << cir ;         cout << "The area of the circle is          :" << are ; }```
• 10-11-2004
Epo
Using:
Code:

`return CalcDist(xc1, xc2, yc1, yc2);`
Would be fine too since the same function does not keep calling itself. All that would happen is that: