Hey everyone,
I'm new on the forums and I'm also quite new still too C++ programming I'm taking a course in it in college (to meet my requirements) Its not my major and I'm terrible at math to boot. I have an assignment where the professor wants us to make a program that calculates the radius area and circumference of a circle based on 4 points the user enters, (the center and two points on the circle) I can get the program to start but when I go to enter numbers the program crashes with the following error:

Run-time error check failure #3- the varriable rad is being used without being initialized.

But I don't believe I need to initialize any of those, heres the code:

#include <iostream>
#include <iomanip>
using namespace std;
// prototypes go here
 double radius(int,int,int,int);
  double circumfrence(double, double);
   double area(double, double);
int main()
{
    int x1;
    int x2;
    int y1;
    int y2;
    double rad;
    double circum;
    double ar;
	double radius1;
	double circumfrence1;
const double pi=3.141616;
cout << "This Program Finds The Area, Radius and Circumfrence of a circle!" << endl;
cout << "Please where the center of the circle is, please enter two numbers " << endl;
cin >>x1;
cin >>y1;
cout << "Please enter a point of the circle, please enter two numbers " << endl;
cin >> x2;
cin >> y2;
radius1 = radius(x2,x1,y2,y1);
cout << "The Radius of the Circle is:" << rad << endl;
area(pi,radius1);
cout << "The Area of the Circle is:" << ar << endl;
circumfrence1 = circumfrence(pi,radius1);
cout << "The Circumfrence of the Circle is:" << circum << endl;
}
double radius(int p2,int p1, int c2, int c1)
{
    double rad;
	
    rad=(p2-p1)*(p2-p1)+(c2-c1)*(c2-c1);
    return rad;
}

double area(double pi, double radius)
{
    double ar;
    ar=pi*(radius*radius);
    return ar;
}

double circumfrence(double pi,double radius)
{
    double circum;
    circum=pi*(radius*2);
    return circum;
}

I believe it has something to either do with my data types, return types or maybe just my equations. Although I am not to sure, any help on this would really be appreciated .

Recommended Answers

All 2 Replies

Please use code-tags the next time...

double rad;
double circum;
double ar;
double radius1;
double circumfrence1;
const double pi=3.141616;
cout << "This Program Finds The Area, Radius and Circumfrence of a circle!" << endl;
cout << "Please where the center of the circle is, please enter two numbers " << endl;
cin >>x1;
cin >>y1;
cout << "Please enter a point of the circle, please enter two numbers " << endl;
cin >> x2;
cin >> y2;
radius1 = radius(x2,x1,y2,y1);
cout << "The Radius of the Circle is:" << rad << endl;

Where is rad written to between these points in your code?
Reread the section in your text on variable scope. There's no relationship between your rad variable in the function and the one in main. Radius1 has what you need.

Thank you, can't believe i didn't see that it makes sense seeing that I didn't actually bring the variable rad to equal anything in the main function and too boot i didn't make rad a reference variable. By the looks of it I did the same thing to the other variables too. Hopefully my math is right :P

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.