C# C# Basics Methods Method Parameters

Shouldn't this be correct code for the question? C#

Check the code, why does it keep saying its wrong?

Program.cs
using System;

class Program
{

    static double Multiply(double first, double second)
    {
        return first * second;
    }


    static void Main(string[] args)
    {
        double total = Multiply(2.5, 2);
        Console.WriteLine(total);
        double total2 = Multiply(6, 7);
        Console.WriteLine(total2);
    }

}

2 Answers

Daniel Turato
PRO
Daniel Turato
Java Web Development Techdegree Graduate 30,112 Points

The challenge requires you not to return the result from multiply but instead output to the console. So you should change the return type on the multiply method from double to void and output the result in that method instead of Main. Otherwise, everything else looks good.

How would it go with that method? Im stuck

How would it go with that method? Im stuck

Daniel Turato
Daniel Turato
Java Web Development Techdegree Graduate 30,112 Points

So your code should look like this

using System;

class Program
{

    static void Multiply(double first, double second)
    {
        Console.WriteLine(first*second);
    }


    static void Main(string[] args)
    {
        Multiply(2.5, 2);
        Multiply(6, 7);
    }

}

using System;

class Program {

static double Multiply(double first, double second)
{
    return first * second;
}

static void Main(string[] args)
{
    double total = Multiply(2.5, 2);
    double total2 = Multiply(6, 7);
    Console.WriteLine(total + (total2));

}

}

That is the code that will pass the challenge dear brothers...