C++ program to check if the range between two numbers is divisible by another number

Sep 6, 2019 at 5:07pm
delete this
Last edited on Sep 6, 2019 at 6:53pm
Sep 6, 2019 at 5:15pm
So let's make sure I got this right. If a = 5 , b = 10 , and c = 2, you want to see if any number between 5 and 10 will be divisible by 2?

If that's the case, the code you have now is fine... Unless you input "a" as a larger number than "b". What's the issue?
Sep 6, 2019 at 5:16pm
I want it to output 1 Yes or 1 No
Sep 6, 2019 at 5:43pm
cout << "1 NO" << endl; //like this?!

a side note, you can drastically reduce the work being done: you don't even need a loop.
the remainder vs the result...
say you want to know if something in 1234 to 1300 is divisible by 9.
1234 % 9 is 1
so we know that if we just added 1 to 1234, it would be divisible.
1235 / 9 = 137
and we know that 1235 is in the range asked for.
we are done. Do you understand this? Modulo is not well taught ... do you get what the remainder represents and why this is true? If you understand that... does anything change if your numbers are sometimes negative?
whole thing becomes if (a+a%c <= b) I believe, for positive input where a < b
Last edited on Sep 6, 2019 at 5:48pm
Sep 6, 2019 at 6:47pm
jonnin Sorry thats not useful
Sep 6, 2019 at 8:10pm
Just funny to see, in a C++ forum

delete this

:)
Sep 6, 2019 at 8:26pm
Well I can't delete it myself so if any mod or anything can delete that would be cool..
Sep 6, 2019 at 8:38pm
typically you leave your question and its answers for others to enjoy. Deleting posts is usually seen as rude, unless the post is spam or unacceptable in some way.

if you do it too much people stop trying to help.

Sep 6, 2019 at 8:45pm
I think what he wanted was break; If he found a number that was divisible, than it should stop the loop.
Sep 6, 2019 at 10:03pm
> say you want to know if something in 1234 to 1300 is divisible by 9.
> 1234 % 9 is 1
> so we know that if we just added 1 to 1234, it would be divisible.
> 1235 / 9 = 137
you've got it backwards
you need to subtract 1 to 1234 so it would be divisible
1233 / 9 = 137

then you may do 1233 + 9 to get a number in the desired range.
Last edited on Sep 6, 2019 at 10:03pm
Sep 6, 2019 at 11:27pm
Deleting posts is usually seen as rude, unless the post is spam or unacceptable in some way.

Someone might actually consider reporting the poster in question.
Sep 7, 2019 at 2:59am
well that would explain why it wasn't helpful. I hate when I do that.
Sep 9, 2019 at 12:15pm
Someone might actually consider reporting the poster in question.

Which, in this case, would be giving the poster exactly what they wanted... in effect, rewarding them for abusing this forum.

Sep 9, 2019 at 4:30pm
Sounds kinky
Topic archived. No new replies allowed.