Hi, new learner to C++. I have to write 4 functions to compute and return the diameter, circumference, etc. of a circle. I think I might be on the right track but I'm probably making this harder than it has to be. I commented most code out because I'd like to get one thing working and then go back and finish. How do I get the radius value into the equation? When I run it the answer comes up
-1.#IND when I put in a radius of 2.

#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std ;

double radius ;
double diam ;
double const PI = 3.14159265358979323846 ;


double diameter(double diam)
{
	double d ;
	while (d = 2 * radius ) 
	return d ;
}

//double circum(double circumf)
//{
//	return diam * PI ;
//}
//
//double area(double area1)
//{
//	return PI * pow(radius, radius) ;
//}
//
//double volume(double vol1)
//{
//	return (4.0/3.0) * (radius * radius * radius) * PI ;
//}



int main()
{
	double radius ;
	
	cout << "Please enter the radius of a circle: " ;
	cin >> radius ;

	double d = diameter(diam) ;
	cout << "The diameter of the circle is: " << d << endl ;

		
	/*circum(circumf);
	cout << "The circumference of the circle is: " << circumf << endl;

	area(area1);
	cout << "The area of the circle is: " << area1 << endl;

	volume(vol1);
	cout << "The volume of the sphere is: " << vol1 << endl;*/



return 0 ;

}

Thank you!

This function isn't doing anything:

double diameter(double diam)
{
	double d ;
	while (d = 2 * radius ) 
	return d ;
}

You're passing in the radius, not the diameter, so your function argument should be named to reflect this.

Also, you're not using the value that you're passing in to the function withing the function's implementation.

There should be no loop, you should just return the diameter, which equals 2*radius (i.e. two times the value that you are passing in to the function).

This function isn't doing anything:

double diameter(double diam)
{
	double d ;
	while (d = 2 * radius ) 
	return d ;
}

You're passing in the radius, not the diameter, so your function argument should be named to reflect this.

Also, you're not using the value that you're passing in to the function withing the function's implementation.

There should be no loop, you should just return the diameter, which equals 2*radius (i.e. two times the value that you are passing in to the function).

Okay...I did this:

double radius(double rad)
{
	return 2 * rad ;
}

Then changed the rest and it worked! Thank you!!!

No problem. Are you able to figure out the others on your own? If so, you might want to mark the thread as solved. reputation/feedback wouldn't hurt either :D

I wanted to make sure I was okay on my own before I marked this solved. I took a little break and started again. I got it figured out. Thank you!

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.