I'm trying to teach myself C++ through internet tutorials and such. Right now I'm trying to write a program that find the diameter and radius of a circle if the circumference is entered, and does the same if one of the other two measurements is entered instead. I'm using switch/case to do this. It won't even compile right, so help me find out what I did wrong, please. I'm hoping it's something basic that will make me put my face through the desk when someone points it out, rather than an error with the design, which is also very possible. :\

``````#include <iostream>

using namespace std;

float radius ( float r, float d, float c );
float diamter ( float r, float d, float c);
float circumference ( float r, float d, float c);

int main()
{
float r, d, c;
int In;

cout<<"Enter one of a circle's measurements. \n";
cout<<"2 - diameter \n";
cout<<"3 - circumference \n";
cin>> In;
switch ( In ) {
case 1:
case 2:
diameter();
case 3:
circumference();
default:
}
cin.get();
}

float radius ( float r, float d, float c )
{
cin>> r;
return d * 2 * r, 2 * 3.14 * r;
}

float diameter ( float r, float d, float c)
{
cin>> d;
return d / 2, 3.14 * d;
}

float circumference (float r, float d, float c )
{
cin>> c;
return c / 3.14, c / 2 / 3.14
}``````

## All 3 Replies

I relooked it several times, and I found an error when I spelled diameter as 'diamter' myself, and I also gave radius, circumference, and diameter capital letters because I figured they might be preloaded functions or keywords or something like that. That seemed to eliminate almost all of the errors in dev C++'s error report thing, but it still tells me

5 too few arguments to function `float Radius(float, float, float)'
21 at this point in file

And that same thing again for lines 6 & 23, and 7 & 25. I don't know what 'too few arguments to function' means.

Alas, you need some (serious) redesign, for example:

``````double radius ( double& r, double& d, double& c );
double diameter ( double& r, double& d, double& c);
double circumference ( double& r, double& d, double& c);

const double Pi = 3.14159265358;

int main()
{
double r, d, c;
int in;

cout << "Enter one of a circle\'s measurements\n"
"2 - diameter\n"
"3 - circumference\n: ";
if (cin >> in) { // test it!
switch ( in ) {
case 1:
break;
case 2:
diameter(r,d,c);
break;
case 3:
circumference(r,d,c);
break;
default:
cout<<"Alas, choice number out of range...\n";
return 1;
}
if (r > 0.0)
cout << "r: " << r << " d: " << d << " c: " << c << endl;
else
cout << "Invalid value <= 0.0 entered...\n";
} else
cout << "Sorry, it\'s not-a-number...\n";
return 0;
}

double radius ( double& r, double& d, double& c )
{
cout << "Enter the radius value: ";
if ((cin >> r) && r > 0.0) { // test it!
d = r + r;
c = Pi * d;
} else // not-a-number
r = d = c = 0.0;
return r;
}
...``````

Make other functions yourself.
PS. Use double type instead of float. It's the best (and fastest) floating-point type of modern CPUs.

Leopold, the issue you're having with "too few arguments" is occuring because you are calling functions with zero inputs that require three inputs.

You call the function radius like this:

``radius();``

Yet the function header for radius determines that the function accepts three numbers (r, d, and c):

``float radius ( float r, float d, float c );``

This is why ArkM changed your function calls to:

``radius(r,d,c);``
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.