ItsMods

Full Version: Number Multiples
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Hi,
I have a Problem:
I want to set up, when a variable self.Test is for Example 7,14,21,28,35 ...
return true.
But how can i do this?
I dont want to code 500 IFs for each number.
Only one for 7 and his multiples.
Hope I explained it good...my english isnt the best
How can i do this?
Thx . Smile
Code:
is7(number)
{
    for(i=0;i<500;i++)
    {
        number2 = number / 7.0;
        if(number2 == i) return true;
    }
    
    return false;
}

Untested

Edit:
Maybe better
Code:
is7(number)
{
    number = number / 7.0;
    number += ""; //string
    if(IsSubStr( number, ".") && !IsSubStr(number,".0")) return false;
    return true;
}
Thx, but if I have 2 AND 4 for example, then it wont work cause every multiple of 4 is a multiple of 2 too. i need a 100 % sure function. cause i need it with more numbers.
but thx Wink
try (self.test % 7 == 0)

Maybe it works.
Ok, better idea. cause 2 is automaticly a multiple of EVERY 4 multiple, so better question:

when I have defined a variable self.Test and i want to say
IF (self.Test == blabla){ do thisshit();}
for example:

PHP Code:
if (self.Test == 1){ do thread 1}
else if (
self.Test == 2){ do thread 2}
else if (
self.Test == 3){ do thread 3}
else if (
self.Test == 4){ do thread 4}
else if (
self.Test == 5){ do thread 5

BUT:
how can i say to continue the "loop" of if clauses?
i mean: if self.Test == 6 do thread 1 again or if self.Test == 9do thread 4 again?

How can i code this without using 5 000 000 IFs?
Nobody knows?
Ok, i wanted to do it like this:
for example i have 3 functions.
when
self.test = 1 do func 1
self.test = 2 do func 2
...

SO
now i did that

if(self.test % 1 == 3)
{do function 1}
if(self.test % 2 == 3)
...
with that it should always do the function one when self.test is 1,4,7,...
but it doesnt works Sad
this function isnt wrking with every number.
when i do
if(self.test % 7 == 5) for example it works ?!
but why it doesnt work with every numbers?
% is the modulus operator. It gets the remainder when you divide a number by the other.
5 % 2 = 1 (5 divided by 2 has a remainder of 1)
(04-20-2011, 01:15)master131 Wrote: [ -> ]% is the modulus operator. It gets the remainder when you divide a number by the other.
5 % 2 = 1 (5 divided by 2 has a remainder of 1)

So it rounds the number down and calculates the amount it rounded down?

So 8/3 would be 2,(2/3). 0,(2/3)*3 = 2 ?



I wonder what this would ever be handy for.
(04-20-2011, 01:27)AZUMIKKEL Wrote: [ -> ]
(04-20-2011, 01:15)master131 Wrote: [ -> ]% is the modulus operator. It gets the remainder when you divide a number by the other.
5 % 2 = 1 (5 divided by 2 has a remainder of 1)

So it rounds the number down and calculates the amount it rounded down?

So 8/3 would be 2,(2/3). 0,(2/3)*3 = 2 ?



I wonder what this would ever be handy for.
I just record the remainder when you divide a number, and you can put it into any variable or if/while/for statement

(04-18-2011, 13:14)Tomsen1410 Wrote: [ -> ]Ok, i wanted to do it like this:
for example i have 3 functions.
when
self.test = 1 do func 1
self.test = 2 do func 2
...

SO
now i did that

if(self.test % 1 == 3)
{do function 1}
if(self.test % 2 == 3)
...
with that it should always do the function one when self.test is 1,4,7,...
but it doesnt works Sad
this function isnt wrking with every number.
when i do
if(self.test % 7 == 5) for example it works ?!
but why it doesnt work with every numbers?
I recommend you to use randomint although it is not proper C program, but it is a GSC code
However, the biggest mistake is you are so bad with if statement...
It should be like this:
Code:
if(self.test % 1 == 3)
{do function 1}
else if(self.test % 2 == 3)
...
Pages: 1 2