-2

I just started learning c# and what classes and objects are. In the code below I want to able to just type c.circle(); and print every information about this circle like radius, area etc., but when I run it, it doesn't give me any output on the console screen.

class Program
{
    static void Main(string[] args)
    {   
        Circle c = new Circle();
        c.circle();
    }
}

class Circle
{
    private double radius = 1.0;

    public void circle()
    {
        getradius();
        getarea();
    }

    public double getradius()
    {   
        return radius;
    }

    public double getarea()
    {
        double area = 3.141 * radius * radius;
        return area;
    }
}
Manfred Radlwimmer
  • 13,257
  • 13
  • 53
  • 62
Samra
  • 7
  • 5
    Use `Console.WriteLine` to write to the console. You aren't calling it, so nothing is written. For example, use `Console.WriteLine(getradius());` rather than `getradius();`. – mjwills Mar 22 '18 at 12:05
  • You don't print anything to the console screen. So nothing appears. Did you expect it to print something? Which line exactly did you think would print something to the console? – nvoigt Mar 22 '18 at 12:06
  • `Circle c = new Circle(); Console.WriteLine("Radius: {0}, Area: {1}", c.getradius(), c.getarea());` and finally you need to keep the console open or it will be too fast and you will not see nothing so write this: `Console.Read();` and now as soon as you type a single character the console will then close. – CodingYoshi Mar 22 '18 at 12:10
  • In addition to what the others have said, your implementation of `.circle` doesn't return a value or display either of the ones it receives from its own calls. – Fabulous Mar 22 '18 at 12:13
  • You likely want to use https://msdn.microsoft.com/en-us/library/system.math.pi(v=vs.110).aspx instead of `3.14`. – mjwills Mar 22 '18 at 12:16

1 Answers1

1

The method "circle()" doesn't print anything to the console. If you want it to print something you could add the following code in the circle method:

Console.WriteLine(getradius());
Console.WriteLine(getarea());
GWigWam
  • 2,013
  • 4
  • 28
  • 34