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 trialJosh Colton
556 PointsI am confused on syntax on how to return something
See this code
using System;
class Program
{
static double Divide(int dividend, int divisor)
return (double)dividend / (double)divisor);
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));
}
}
1 Answer
joelearner
54,915 PointsHi Josh,
I tested your code. There were a couple issues and they are relatively simple to fix :)
First, place a set of curly braces to encompass the method statement(s). You can look at the main method as a reference example of the proper syntax here.
Then, place a single open parenthesis before the (double)dividend. If you count the parentheses, you will see 2 open and 3 closed, once you have the curly braces in place.
Your revised code should look something like this:
static double Divide(int dividend, int divisor)
{
return ((double)dividend / (double)divisor);
}
Cheers!