Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

C# C# Basics Methods Return Values

Justin Amyx
Justin Amyx
2,280 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,280 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

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,280 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.