12,824,299 members (40,755 online)

Email

Password

Sign in with

Hello.

This is a homework so don't give me the answer.

IM going to do a program that look in to every numerator and denominator from 1 -100 in both numerator and denominatorf the quotient is = 5 then the numerator and denominatorf will be typed out on the screen.

this is what i have done. Only geting to show denominatorf the quotient to 1- 100.

I know that i need to put in a new int and then count out the = 5 in the if but i dont really know how to do it can any one help me whit it.

Sorry for the bad english

This is a homework so don't give me the answer.

IM going to do a program that look in to every numerator and denominator from 1 -100 in both numerator and denominatorf the quotient is = 5 then the numerator and denominatorf will be typed out on the screen.

```
int num1, num2;
for (num1 = 1; num1 <= 101; num1++)
{
for (num2 = 1; num2 <= 101; num2++)
{
if (num1 + num2 == 101)
Console.WriteLine(num1 + " / " + num2);
}
}
Console.ReadLine();
}
}
}
```

this is what i have done. Only geting to show denominatorf the quotient to 1- 100.

I know that i need to put in a new int and then count out the = 5 in the if but i dont really know how to do it can any one help me whit it.

Sorry for the bad english

Tommy116451

Comments

You are looping through all 100 "num2" for every "num1". That logic will not work. Hope that helps.

the program going to loop through 1-100 100-1 and every time the quotient is = 5 the two number and = 5 going to show on the screen for example 10/2 and that is going on the console screen

v2

Comments

if i understand what you are trying to say. than you should use %5

eq if 25 % 5 is zero than show on screen

eq if 25 % 5 is zero than show on screen

int num1, num2, sum;

for (num1 = 1; num1 <= 101; num1++)

{

for (num2 = 1; num2 <= 101; num2++)

{

if ()

Console.WriteLine(sum);

}

}

Console.ReadLine();

i have tried a lot of diffrent stuff but not the right one of course becous it only com up that i need to use a bool in this but i beliwe you can do this white out a bool. like this under the if statment sum = num1 / num2 and then change the int sum = 5; but what im i going to put in to the if() that is what a troubling me

for (num1 = 1; num1 <= 101; num1++)

{

for (num2 = 1; num2 <= 101; num2++)

{

if ()

Console.WriteLine(sum);

}

}

Console.ReadLine();

i have tried a lot of diffrent stuff but not the right one of course becous it only com up that i need to use a bool in this but i beliwe you can do this white out a bool. like this under the if statment sum = num1 / num2 and then change the int sum = 5; but what im i going to put in to the if() that is what a troubling me

First of all this is looping through 1-101 (not 100).

The next question is: must the quotient be 5 AND the remainder == 0?

(I'd guess that is what you want.)

So use the % operator to get the remainder, OR use the Math.DivRem(...) method to get both quotient and remainder at the same time.

I'd also suggest renaming the variables to more meaningful names: numerator, denominator, quotient, remainder, ...

The next question is: must the quotient be 5 AND the remainder == 0?

(I'd guess that is what you want.)

So use the % operator to get the remainder, OR use the Math.DivRem(...) method to get both quotient and remainder at the same time.

I'd also suggest renaming the variables to more meaningful names: numerator, denominator, quotient, remainder, ...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject,
503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada
+1 416-849-8900 x 100