2
I’m trying to do an exercise where in a range of 0 to 30 I want to know which numbers are divisible by 3 or 4. Working with a if
for every situation works. But if I try to use the logical operator ||
does not work. It is part of the code that is commented.
private void button5_Click(object sender, EventArgs e)
{
int iA;
for (iA = 0; iA <= 30; iA++)
{
//if (iA % 3 == 0 || iA % 4 == 0);
//{
// MessageBox.Show(iA + " é múltiplo de 3 ou de 4");
//}
if (iA % 3 == 0)
{
MessageBox.Show(iA + " é múltiplo de 3");
}
else if (iA % 4 == 0)
{
MessageBox.Show(iA + " é múltiplo de 4");
}
}
}
Typo is not within the scope of the SE
– jean
Did any of the answers solve your question? Do you think you can accept one of them? Check out the [tour] how to do this, if you haven’t already. You would help the community by identifying what was the best solution for you. You can accept only one of them. But you can vote on any question or answer you find useful on the entire site.
– Maniero