C# C# Basics Methods Return Values

Justin Amyx
Justin Amyx
2,261 Points

I broke the C# basics test for Methods (final coding challenge)

So I've spent hours now going over all of this, but with my current knowledge I can not for the life of me figure this

Program.cs
using System;

class Program
{

    static double Multiply(double firstParam, double secondParam)
    {
       return (2.5 * 2 + 6 * 7);

    }

    static void Main(string[] args)
    {

       Console.WriteLine();

    }

}
Justin Amyx
Justin Amyx
2,261 Points

So that we are aware. When this is run, it actually displays the message that you would get for failing the check work button.

I'm very confused by what exactly is being asked here and am struggling to research a solution that makes the program do what the test is asking.

1 Answer

<noob />
<noob />
16,609 Points

Hello bro what sup? You have few basic mistakes ill try to explain. in the Multiply method ur being asked to return the value of the first and the second params.

   static double Multiply(double firstParam, double secondParam)
    {
        return firstParam * secondParam;
    }

as u see we have 2 parameters and we return the multiply value of them.

after that ur being asked to add the two calls to the function toghter. You just need to declare 2 variables, 1 for the first call and the second to the second call and print the result of adding them toghter with the Console.WriteLine() method.

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

}

As u can the variable first stores the value 5 because we call the Multiply function with 2 arguments 2.5 and 2. in the Multiply method they being sent and the method returns the result of the multipy operator.

You just need to know that we use parameters as placeholders because we want to reuse the function, arguments are the values u call the function with.

hope this helps

Justin Amyx
Justin Amyx
2,261 Points

It's so simple when you explain it! Thank you so much! I knew I was missing lines but I could not for the life of me figure out how to format it.