+ 1

Coding help! C# VS

So, I'm trying to make a factor machine, which I have all the code expect I don't know how to find the factor. So you could pick 6, 1, 2, 3, 6. Here's what I think the code could be. int x = Microsoft.VisualBasic.Interaction.InputBox("Factor", "yes"); int a; for (int i = 0; i < x; i++;) { if (x % 2 == x ) { a = x; lstData.Items.Add("Factors: " + a); } }

12th Sep 2018, 4:06 PM
Ethan
Ethan - avatar
3 Réponses
+ 1
If I understood you correctly, your loop should've been like this instead; for (int i = 2; i < x; i++) { if (x % i == 0) { lstData.Items.Add("Factors: " + i); } } Explanation: I initialized i with 2 in the for loop because we know a number divided by 1 leaves no remainder, thus we can skip 1 altogether, and dividing by zero is totally prohibited, modulo internally do division and returns the remainder of the division operation (cmiiw). Hth, cmiiw
17th Sep 2018, 3:20 AM
Ipang
+ 1
thanks
17th Sep 2018, 9:48 AM
Ethan
Ethan - avatar
+ 1
You're welcome : )
17th Sep 2018, 9:50 AM
Ipang