C# C# Basics Methods Method Parameters

Brittney Coble
Brittney Coble
16,335 Points

C# Basics Multiply Method, why does this code not work?

I am not sure why this code doesn't work. It seems to match the hints so I'm not sure how to proceed.

Program.cs
using System;

class Program
{

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

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

}

2 Answers

KRIS NIKOLAISEN
KRIS NIKOLAISEN
54,172 Points

According to the instructions Console.WriteLine should be in your Multiply function instead of the Main method.

Brittney Coble
Brittney Coble
16,335 Points

Thanks Kris. Finally got it with this"

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 number1, double number2)
    {
        double result = number1 * number2;
        Console.WriteLine(result);
    }

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

}