Originally Posted by
jocdrew21
getdata is not returning anything. Functions do not work like that. I think you would be interested in using a class.
Nonsense. A function can return something or it can not. Nothing is wrong with either approach.
Substituting with a class when you are just going to call one member function and which does not even contain any member data is pointless.
Onwards to errors...
Code:
const float PI = 3.14159f;
void getdata(float &);
float volume(float);
float surface_area(float);
float cross_section(float);
float circum(float);
float height(float);
void putdata(float, float, float);//writes the radius plus two resuts
Don't remove the parameter names from the prototype declarations. This is considered bad practice.
They also don't match the definitions. That's an error.
Code:
void getdata(float & radius)
{
cout << cout << "Enter character V to find volume of a sphere, A to find the area, and X to find the Cross Section Area. Follow character input with radius and then wither height or circumference. End program by inputting Q.\n" << endl;
cin >> input;
}
Don't output twice to cout. It should only be once.
radius parameter is unused and input is undeclared. You should either return the input value or read into the correct parameter (e.g. radius).
Code:
float volume(float r & h)
{
return PI*h*r*r;
}
Syntax error in function definition. "float r & h" is not valid syntax. Did you mean to say that the function accepts two arguments? If so, you mean to write "float r, float h".
Code:
float surface_area(float r & c)
{
return (PI*r*r * 2) + (c*h);
}
Same syntax error as before. h is undeclared. Did you forget to pass it as an argument?
Code:
void putdata(float radius, float c, float h, float v, float a, float x)
Misleading name. Probably should be something along the lines of "printdata".
Last, but not least, format and indent your code properly:
Code:
#include <iostream>
#include <cmath>
using namespace std; //intriduces namespace std
const float PI = 3.14159f;
void getdata(float &);
float volume(float);
float surface_area(float);
float cross_section(float);
float circum(float);
float height(float);
void putdata(float, float, float);//writes the radius plus two resuts
int main(void)
{
float radius, c, h, v, a, x;
getdata(radius);
c = circum(radius);
h = height(radius);
v = volume(radius);
a = surface_area(radius);
x = cross_section(radius);
putdata(radius, c, h);
system("pause");
return 0;
}
void getdata(float & radius)
{
cout << cout << "Enter character V to find volume of a sphere, A to find the area, and X to find the Cross Section Area. Follow character input with radius and then wither height or circumference. End program by inputting Q.\n" << endl;
cin >> input;
}
float volume(float r & h)
{
return PI*h*r*r;
}
float surface_area(float r & c)
{
return (PI*r*r * 2) + (c*h);
}
float cross_section(float r)
{
return PI*r*r;
}
void putdata(float radius, float c, float h, float v, float a, float x)
{
cout << "Raduis =" << radius << endl;
cout << "Circumference =" << c << endl;
cout << "Volume =" << v << endl;
cout << "Surface Area =" << a << endl;
cout << "Cross Section =" << x << endl;
}