by looking at the code below you can see that I doing is finding out if a number is a multiple of another number, by either 11 or 13, what I am trying to find out is how to make it so if a blocker number is in between them then to stop going down that path, I'll try to explain what I mean by that below the first piece of code.
for (int i = 1; i<=7; i+=1)
{
if (newNumber == lastNumber - (i * 11) || newNumber == lasNumber + (i * 11) || newNumber == lastNumber - (i *13) || newNumber ==lastNumber + (i * 13))
{
sayNumber();
}
}
lets say newnumber is 11 and lastnumber is 55, and there is a blocking number at 33, this would be a false statement because 55 - i reaches the blocker number first. Should I split this if loop into 4 different statements and test this 1 at a time, or is it easier to test everything at the same time?
Last edited by polyneem on Wed May 19, 2010 11:59 am, edited 1 time in total.
If you are trying to work out whether a number is a multiple of another number you are going about it the wrong way. I'm not 100% sure what you are asking but I hope this helps:
see % operator (modulus).
you can even go on google and try it out, google this:
26%13
try changing the numbers about look up what modulus is and you should be able to work it out.
polyneem wrote:by looking at the code below you can see that I doing is finding out if a number is a multiple of another number, by either 11 or 13, what I am trying to find out is how to make it so if a blocker number is in between them then to stop going down that path, I'll try to explain what I mean by that below the first piece of code.
for (int i = 1; i<=7; i+=1)
{
if (newNumber == lastNumber - (i * 11) || newNumber == lasNumber + (i * 11) || newNumber == lastNumber - (i *13) || newNumber ==lastNumber + (i * 13))
{
sayNumber();
}
}
lets say newnumber is 11 and lastnumber is 55, and there is a blocking number at 33, this would be a false statement because 55 - i reaches the blocker number first. Should I split this if loop into 4 different statements and test this 1 at a time, or is it easier to test everything at the same time?
A few points to remember:
1. "if loop": The if statement is a conditional structure, not a looping structure - watch your terminology.
2. When incrementing values by one, it is generally a good idea to use ++i (e.g. for(int i = 1; i <= 7; ++i))
3. If I understood your question correctly, the following will achieve the same end result as your single if statement:
@Genesis I know about the ++ and -- but previously I was using different numbers and the += was an efficient way to change the number, your code was what I was thinking of changing to, but what the big thing that I am trying to ask is really tough to get across.
I'll try explaining it with text instead of code this time.
if I have a number set at 11 and another number set at 55, and a number to stop the counting set at 33, I then tell the program to decrement 55 by 11 until it either reaches 33 or it reaches 11, I want it to stop the loop at 33 and at 11 I want it to call a function.
Is that explained better? I must apologise for the misunderstanding I've never been good at trying to get my message across. After rewriting my question has given myself some new ideas on how to approach the problem.
never mind, I thank you all for your help, but its too hard for me to explain what I want to do, when I figure it out I'll post what the solution was and then maybe we can create a question to help me explain myself better in the future, I once again thank you all for your time.