Posts: 1,185
Threads: 72
Joined: Jan 2011
Reputation:
25
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 .
Posts: 5,135
Threads: 241
Joined: Nov 2010
Reputation:
100
03-29-2011, 20:31
(This post was last modified: 03-29-2011, 20:45 by Pozzuh.)
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;
}
Posts: 1,185
Threads: 72
Joined: Jan 2011
Reputation:
25
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
Posts: 3,598
Threads: 265
Joined: Oct 2010
Reputation:
76
03-29-2011, 22:01
(This post was last modified: 03-29-2011, 22:02 by SuperNovaAO.)
try (self.test % 7 == 0)
Maybe it works.
Posts: 1,185
Threads: 72
Joined: Jan 2011
Reputation:
25
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?
Posts: 1,185
Threads: 72
Joined: Jan 2011
Reputation:
25
Posts: 1,185
Threads: 72
Joined: Jan 2011
Reputation:
25
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
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?
Posts: 719
Threads: 69
Joined: Nov 2010
Reputation:
76
% 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)
A casual conversation between barata and I about Nukem.
Posts: 4,530
Threads: 254
Joined: Nov 2010
Reputation:
65
(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.
Posts: 51
Threads: 1
Joined: Apr 2011
Reputation:
1
04-20-2011, 10:38
(This post was last modified: 04-20-2011, 10:41 by Xeonic.)
(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
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)
...
The best way to hide is to change yourself
|