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 Method Parameters

michael edmondson
michael edmondson
4,511 Points

Hey im getting 5 and 42 as my results can somebody tell me whats wrong with my code?

Program.cs
using System;

class Program
{

    // YOUR CODE HERE: Define a method named Multiply. Remember
    // to use the "static" and "void" keywords: "static void
    // Multiply" (without quotes). Multiply should take two
    // "double" values as parameters.
    static double Multiply( double one, double two)
    {
        return one * two;
    }

    static void Main(string[] args)
    {
        // YOUR CODE HERE:
        // Call Multiply with two arguments: 2.5 and 2.
        // YOUR CODE HERE:
        // Call Multiply with two arguments: 6 and 7.
        Double total = Multiply(2.5,2);
        Console.WriteLine(total);
        Double total2 = Multiply (6,7); 
        Console.WriteLine(total2);
    }

}

2 Answers

There is no return value so you don't need the assignment to variable total. And the Multiply function now handles writing to the console. All you need is to call the functions like this:

    Multiply(2.5,2);
    Multiply(6,7);   

Instead of return the task wants Console.WriteLine in the Multiply function. Use the static and void keywords in the method definition.

Then in Main you just call the function with the provided values

michael edmondson
michael edmondson
4,511 Points

hey this is my new code but im still getting an error

using System;

class Program {

// YOUR CODE HERE: Define a method named Multiply. Remember
// to use the "static" and "void" keywords: "static void
// Multiply" (without quotes). Multiply should take two
// "double" values as parameters.
static void Multiply( double one, double two)
{
    Console.WriteLine(one * two);
}

static void Main(string[] args)
{
    // YOUR CODE HERE:
    // Call Multiply with two arguments: 2.5 and 2.
    // YOUR CODE HERE:
    // Call Multiply with two arguments: 6 and 7.
    total = Multiply(2.5,2);
    Console.WriteLine(total);
    total2 = Multiply (6,7); 
    Console.WriteLine(total2);
}

}