15,997,116 members

See more:

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.

C#

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

Comments

Richard C Bishop
29-Jan-13 10:45am

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

Permalink

Share this answer

v2

Comments

Transitional
29-Jan-13 10:50am

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

Tommy116
29-Jan-13 11:01am

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

Matt T Heffron
29-Jan-13 16:32pm

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, ...

i tryd to put in

put it show only one side of it and it dont showe the right answer only on the 2 first and then it do what it whant

C#

if (num1 / num2 == 5) Console.WriteLine(num1+"/"+num2);

put it show only one side of it and it dont showe the right answer only on the 2 first and then it do what it whant

Permalink

Share this answer

Comments

Matt T Heffron
29-Jan-13 16:33pm

(See my note above about the remainder == 0)

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

CodeProject,
20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8
+1 (416) 849-8900