tag mismatch -
Emre__ - 20.01.2013
Hello everyone,
I've created a new function and when I call it I get the error message as title.
pawn Код:
forward IsDivisible(the_number, divided_by);
public IsDivisible(the_number, divided_by)
{
while(the_number > 0) the_number -= divided_by;
if(!the_number) return true;
return false;
}
pawn Код:
if(IsDivisible(100, 3) == false) // the warning line.
printf("This value can not be divised by 3");
Please help me about it. Thanks.
Re: tag mismatch -
[XST]O_x - 20.01.2013
Just wondering, why using this function, when you've got modules?
You can use:
pawn Код:
if(num%3) == 0 //num devides by 3 with no remainder
else //num does not devide by 3 with no remainder.
Way simpler.
Re: tag mismatch -
Emre__ - 20.01.2013
Are you sure that it's working? 'cuz I couldn't make it work. That's why I created the function.
Re: tag mismatch -
[XST]O_x - 20.01.2013
Quote:
Originally Posted by Emre__
Are you sure that it's working? 'cuz I couldn't make it work. That's why I created the function.
|
Of course.
Module is used many times.
Anyway if you still want to use your function just replace "if(...) == false" with "if(...) == 0".
And show me what you wanted to do with modules that didn't work out for you?
Re: tag mismatch -
Emre__ - 20.01.2013
I changed "== false" to "== 0" and it didn't return any warning messages, so my function is working properly.
pawn Код:
if(100%3) == 0
printf("This value can not be divised by 3");
What's wrong with the module.
Re: tag mismatch -
[XST]O_x - 20.01.2013
Quote:
Originally Posted by Emre__
I changed "== false" to "== 0" and it didn't return any warning messages, so my function is working properly.
pawn Код:
if(100%3) == 0 printf("This value can not be divised by 3");
What's wrong with the module.
|
Okay, after looking up a bit, it appears that pawn has some issues with modulus, and they're not really working.
I was mistaken because I used to use modulus when I scripted in C++, so I thought pawn also supports them.
My bad. Use your function then.
Re: tag mismatch -
Emre__ - 20.01.2013
Thank you for your help.
Re: tag mismatch -
Vince - 20.01.2013
Uh, the modulus works just fine. 100 % 3 is 1. Your code is a fail.
Re: tag mismatch -
LarzI - 20.01.2013
I believe it happens because as you didn't set a tag for the function, it's automaticly "converting" false to 0 and true to 1.
If I'm correct about this, I think putting a bool tag infront of the function would fix this (at least that seems logical to me):
pawn Код:
forward bool:IsDivisible(the_number, divided_by);
public bool:IsDivisible(the_number, divided_by)
{
while(the_number > 0) the_number -= divided_by;
if(!the_number) return true;
return false;
}
But modulus should work just fine, as Vince stated.
Re: tag mismatch -
[XST]O_x - 20.01.2013
Quote:
Originally Posted by Vince
Uh, the modulus works just fine. 100 % 3 is 1. Your code is a fail.
|
!
How did I miss that? God O_O