lundi 14 décembre 2020

C++ functions with pointers

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);
}

Aucun commentaire:

Enregistrer un commentaire