Home > Blockchain >  I am trying to calculate side C of a triangle using pythagoras, using a class.. C#
I am trying to calculate side C of a triangle using pythagoras, using a class.. C#

Time:12-23

This is the last assignment of my C# course.. In this assignment i program using a class. I can make this all work without use of a class, but can not (thusfar) with.

here is the code:

public class Pyt
{

    public Pyt (double rh1, double rh2)

    {

    _Rh1 = rh1;
        _Rh2 = rh2;
     

        }

private double _Rh1;
private double _Rh2;


public double _Som()

{

        return _Rh1 * _Rh1   _Rh2 * _Rh2;
    }

    public double _Som2()

    {

        return Math.Sqrt(_Som);///here is where the problems arise.. at the last
    }
                                  /// calculation.. it gives error, can not convert from 
}                                 ///method group to double.

}

as you might have read, it gives error can not convert from method group to double.

I have thusfar tried several things, my method seems ok (using 2 sum variables)

Can anybody help?

greetings,

Stefan

CodePudding user response:

_Som is just the function. You want to caculate the square root on the result of the function. To do that you need to invoke the function using the parenthesis.

public double _Som2()
{
    return Math.Sqrt(_Som());
}

CodePudding user response:

In your code, _Som is a function for calculating the sum of squares of the two sides. You can't take the square root of a function.

You have to use the function by calling it, and take the square root of the result that the function returns.

  • Related