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 Numbers Numeric Types and Casting

Practicing type conversion

Hi guys! Seems I'm only stuck on a small detail, I've gone over the video again, but not getting it yet. Thanks

Program.cs
using System;

class Program
{

    // YOUR CODE HERE: Define a Divide method!
    static double divide(firstNum, secondNum){
int wholeNumber = (int)5.0;
double fractionalNumber = 2.0;
Console.WriteLine(wholeNumber.GetType());
Console.WriteLine(fractionalNumber.GetType());
        return;
    }
    static void Main(string[] args)

    {
        // This should print "2.5".
        Console.WriteLine(Divide(5, 2));
        // This should print "3.3333333333..."
        // (Or a value close to that, since it can't be
        // infinitely precise.)
        Console.WriteLine(Divide(10, 3));
    }

}

Forgot to add the error I'm getting. "error CS1001: Identifier expected"

1 Answer

Steven Parker
Steven Parker
229,732 Points

It looks like there are a few issues:

  • the parameter types must be declared with their names ("(int firstNum, int secondNum)")
  • the method name should be "Divide" (with a capital "D") instead of "divide"
  • the parameters should be used in the calculation
  • you won't need to create any new variables
  • the final result must be return‍ed
  • you won't need to output ("WriteLine") anything

Hey Steven, just got to update my code

using System;

class Program {

// YOUR CODE HERE: Define a Divide method!
static double Divide(int param1 2.5 , int param2 2.0)
{
    int param1 = (int) 2.5;
    double param2 = 2.0;
    return(Divide);
}

static void Main(string[] args)
{
    // This should print "2.5".
    Console.WriteLine(Divide(5, 2));
    // This should print "3.3333333333..."
    // (Or a value close to that, since it can't be
    // infinitely precise.)
    Console.WriteLine(Divide(10, 3));
}

}

The only error I'm getting now is " Program.cs(7,37): error CS1003: Syntax error, ',' expected [/workdir/workspace.csproj] Program.cs(7,54): error CS1003: Syntax error, ',' expected [/workdir/workspace.csproj] "

Steven Parker
Steven Parker
229,732 Points

Several issues still need to be addressed, but now there's some new causes:

  • the parameter declarations should only have types and names (like "(int firstNum, int secondNum)")
  • the parameters should still be used in the calculation
  • you won't need to create any new variables (particularly not ones with the same names as the parameters)
  • the final calculation result must be return‍ed (not the method itself)

You may also want to review method syntax in the video before trying again.