How do I calculate correct with Modulus %? C# Console App

how do I get the correct output when doing equations with modulus? This is made in a Console Application.

For example:

float equation = (35 + 5) % 3;

output: 1, when the correct answer should be 1.2.

I've tried float equation = (35 + 5) % 3f;

or

Console.WriteLine((float)equation);

But I dont really know how to make it work. Super grateful for any response.

1 answer

  • answered 2021-09-23 09:06 UHM

    Modulus give you the rest of an integer division:

    40/3 = 13
    13 * 3 = 39
    40 - 39 = 1 
    

    1 is the rest

How many English words
do you know?
Test your English vocabulary size, and measure
how many words do you know
Online Test
Powered by Examplum