Start New Discussion within our Software Development Community


this is a homework so please dont give me the answer to the problem.

            int num1, num2;
            for (num1 = 1; num1 <= 101; num1++)
                for (num2 = 1; num2 <= 101; num2++)
                    if (num1 / num2 == 5)
                        Console.WriteLine(num1 + "/" + num2);

this is what i have so far. the 2 numbers that com up first is right but then its relly get wrong. I want it to be every time the 2 numbers have the quotient of 5 the 2 numbers will com up on the screen. like if 10/2 = 5 then the 10/5 will com up.

sorry for my bad english

Since num1 and num2 are integers, I suspect the output of num1 / num2 is being cast as an integer, which is giving you a bunch of wrong outputs, since any output that equals 5 to 5.99999999 will be converted to 5, and equate to true, in if (num1 / num2 == 5). Try casting the output as double, that way only the outputs that equal 5.0, will equate to true.

it type out rigt the first to like
but then it write 11/2, 15/3 and so on

This article has been dead for over six months. Start a new discussion instead.