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 trialaryn weatherly
4,454 Pointsconvert int to double
I've tried working this several different ways and keep making things worse and worse. please help
using System;
class Program
{
// YOUR CODE HERE: Define a Divide method!
static double Divide(int dividend, int divisor)
{
(double)dividend;
(double)divisor;
return (double)dividend/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
Steven Parker
231,198 PointsYou mostly have it, just remove the two lines before the return. The compiler message was trying to tell you that you can't have values by themselves as a statement (nor do you need them).
aryn weatherly
4,454 Pointsthank you so much
Steven Parker
231,198 Pointsaryn weatherly — Glad to help. You can mark the question solved by choosing a "best answer".
And happy coding!
aryn weatherly
4,454 Pointsaryn weatherly
4,454 PointsHey there so I know how terrible my code looks but I've been up all night and im just not getting this for some reason. I'm a bit stuck on the "Let's practice type conversion. Define a Divide method that takes two int values as parameters, and returns the result of dividing them as a double value. For example, Divide(5, 2) should return 2.5. (Normally, a method like this should probably take double parameters, but we want to practice converting values from int to double.)
You'll need to convert each of the int values to double before performing the division operation, so you don't lose the fractional portion of the result." problem.