C# C# Basics (Retired) Perfect Integers and Doubles

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

ultan gannon
ultan gannon
4,128 Points

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