- Randomly generate the
*second*(integer) number, say`n2`

. - Randomly generate an integer
*factor*, say`f`

. - Let the
*first*number, say`n1`

, be equal to*second*number multiplied by the factor`f`

(namely`n1 = n2 * f`

)

15,506,563 members

See more:

Hello, how can I set my WPF Application with random generator number for division without residue? I try to create a math game in which the user chooses the math operation he wants to calculate, then he chooses what level he wants. Addition, subtraction and multiplication are not a problem. The problem occurs during division.

I would like to see only numbers that have no remainder after division. I created the code shown below.

I would like to see only single-digit numbers that would be divided and the result must not be with the residue.

firstNumber would be: 1,2,3,4,5,6,7,8,9

secondNumber would be: 1(divides all),2(divides 2,4,6,8),3(divides 3,6,9),4(divides 4,8)

Wouldn't there be a more sophisticated solution?

**What I have tried:**

I would like the values to be single digits. This code still does not guarantee me without erroneous calculations.

Thank you for any advice

I would like to see only numbers that have no remainder after division. I created the code shown below.

I would like to see only single-digit numbers that would be divided and the result must not be with the residue.

firstNumber would be: 1,2,3,4,5,6,7,8,9

secondNumber would be: 1(divides all),2(divides 2,4,6,8),3(divides 3,6,9),4(divides 4,8)

Wouldn't there be a more sophisticated solution?

C#

int maxValue = 10; Random number = new Random(); int total = 0; int firstNumber = number.Next(1, maxValue); int secondNumber = number.Next(1, maxValue); if (firstNumber < secondNumber) { secondNumber = number.Next(1, firstNumber); } int residue = (firstNumber % secondNumber); if (residue != 0) { firstNumber = firstNumber + 1; } else { total = firstNumber / secondNumber; }

I would like the values to be single digits. This code still does not guarantee me without erroneous calculations.

Thank you for any advice

Comments

A very approach is by construction:

- Randomly generate the
*second*(integer) number, say`n2`

. - Randomly generate an integer
*factor*, say`f`

. - Let the
*first*number, say`n1`

, be equal to*second*number multiplied by the factor`f`

(namely`n1 = n2 * f`

)

Permalink

Share this answer

Comments

Member 15170612
4-May-21 4:30am

is there any way to ensure that the first and second numbers are single digits?

CPallini
4-May-21 4:48am

Of course there is (maybe changing drastically the approach) but then, you have a very little freedom (1 divides all {1..9} range, 2 divides only {2,4,6,8}, 3 divides only {3,6,9}, 4 divides only {4,8}, all the other single digit numbers just divide themselves).

Member 15170612
4-May-21 4:56am

when I set the factor to 1, the division result will always be one, so I would somehow like to combine it

Quote:How can I set division without residue?

A division is:

`dividend`

/ `divisor`

= `quotient`

Draw

`divisor`

and `quotient`

, and multiply them to deduce the `dividend`

.
Permalink

Share this answer

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

I think you should start both sequences at 2 rather than 1.