Reputation: 13
What is the error? How to solve it? This code is to find the area of the circle using pointers and functions. The error I am facing is that the &answer
cannot be converted into float.
#include <iostream>
using namespace std;
void area(float, float);
int main()
{
float radius, answer = 0.0;
cout << "Enter a radius:"; // Take the radius from the user.
cin >> radius;
area(&radius, &answer);
cout << "Area of circle is:" << answer;
return 0;
}
void area(float *value, float *result) // This is the function to calculate the area.
{
*result = 3.142 * (*value) * (*value);
}
Upvotes: 0
Views: 109
Reputation: 641
You can do one of the 2 things:
void area(float*, float*);
void area(float *value, float *result) // This is the function to calculate the area.
{
*result = 3.142 * (*value) * (*value);
}
above the main()
function. Either of these will work.
Upvotes: 2