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 (Retired) Perfect Integers and Doubles

Why is y not 2.33333333 if its a double?


2 Answers

Hi Ultan,

Is it the question with this code?

int a = 3;
int b = 2; 
double c = 3.5; 
double y = a / b * c;

The division and multiplication will be done left to right.

You have

double y = 3 / 2 * 3.5;

Since a and b are both integers, integer division will be performed and the result would be 1. The decimal is truncated.

Then you have 1 * 3.5 and the answer would be 3.5

Thanks Jason I worked it out by looking at other people's questions here. It was an obvious mistake, I was focused on the double and int parts and not thinking about the orders