hello

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.

Answered by tinstaafl 1,161 in a post from

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 / …

All 4 Replies

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
5/1
10/2
but then it write 11/2, 15/3 and so on

i fix it

Good, please mark it as solved. thank you.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.