Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

Am I doing something wrong in C#?

Okay so I have established the following integers: x=10, y=5, z=3, w=2

and I need to find the value of x / z * y

or 10/3 *5

Now when I hit run I get 11 but when I do this on my calculator I get 16.67 or 16 2/3 so which one would be the correct answer?

Also how would I enter this w *= y + z into my Console.WriteLine

Thanks for helping me understand C#

1 Answer

Relevance
  • Jasper
    Lv 5
    7 years ago
    Favorite Answer

    since they're all integers, computer will evaluate: 10 / 3 = 3 (instead of 3.33)

    you gotta pass those numbers as float variables!

    Try this:

    float RES = (float) x / y * z;

    For the second point:

    Console.WriteLine(w.ToString());

Still have questions? Get your answers by asking now.