A few things... (see comments in code)
First, "system pause" requires the "cstdlib" library.
Second, your prototypes are correct, but you must also include the arguments when calling a function. You need to tell the function what variables it is dealing with when using the function.
When calling getRadius(), you must tell the function that it is dealing with the variable "i", so we put:
radius = getRadius(i);
Since "i" is now a variable being using in main, we must also declare "double i" in main along with your other variables.
Thirdly, in your function description of getRadius, you may declare "double i" in the parameters (just like you did with all the other functions.
ALWAYS REMEMBER: Your prototype tells your function what it is going to look like and your arguments tells main what variables the function is going to be dealing with.
All these are corrected and commented in the code below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
|
#include <iostream>
#include <cstdlib>//include for system pause
using namespace std;
double getRadius(double);
double findArea(double);
double findCircumference(double);
int main()
{
double radius;
double area;
double circumference;
double i;//include i in main
radius = getRadius(i);//must include i as an argument
area = findArea(radius);
circumference = findCircumference(radius);
cout << "A circle of radius " << radius << " has an area of: " << area <<endl;
cout << "and a circumference of: "<< circumference << endl;
system("pause");
return 0;
}
double getRadius(double i)
{
cout<<"Please enter the radius of the circle."<<endl;
cin>>i;
return i;
}
double findArea(double radius)
{
double i2;
i2=3.14159*radius*radius;
return i2;
}
double findCircumference(double radius)
{
double i3;
i3=2*3.14159*radius;
return i3;
}
|