C# C# Basics Methods Method Parameters

michael edmondson
michael edmondson
3,369 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

KRIS NIKOLAISEN
KRIS NIKOLAISEN
54,172 Points

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
3,369 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);
}

}

KRIS NIKOLAISEN
KRIS NIKOLAISEN
54,172 Points

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);