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

Jiho Song
Jiho Song
16,469 Points

what is the answer?

I try to find the answer but couldnt after several attempts. what is the output?

Steven Parker
Steven Parker
231,269 Points

This quiz has 7 questions.

Which question is giving you trouble?

Jiho Song
Jiho Song
16,469 Points

Last one open question

1 Answer

Steven Parker
Steven Parker
231,269 Points

:point_right: Let's break it down into steps:

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

Since multiply and divide have equal precedence and left-to-right associativity, the first thing that will happen is: a / b. These are both integers, and integer math produces integers, so: 3 / 2 = 1. Next, the 1 will be multiplied by 3.5, leaving it unchanged since it is a double and being assigned to a double. So the final result wil be: 3.5.

Be aware that some quizzes scramble the question order each time they are used, so it's always best to cut and paste the actual question to identify the one you are working with.

Jiho Song
Jiho Song
16,469 Points

Thanks now I understand!!