SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 29/01/2010, 07:18 PM   #1
CHC
Little Clucker
 
Join Date: Sep 2009
Posts: 6
Reputation: 4
Default New to pawn, trying to convert some C code to pawn

I'm trying to convert this to pawn but i'm having troubles, its not returning the proper percentage, and doesn't change based on if there are more or less caps, does anyone know whats wrong?

Code:
CHC_IsUpper(ch) {
if(ch>64&&ch<91) return 1;
return 0;
}
//C
float TooManyCaps(char *name) {
int num=0;
char *x=name;
float final;
int size=strlen(name);
while(size--) {
if(CHC_IsUpper(*x++)) num++;
}
final=(float)num/(strlen(name)-1);
return (float)final*100;
}
//PAWN
TooManyCaps(name[]) {

new Float:caps,num,sz;
sz=strlen(name[0]);
while(sz--) {
if(CHC_IsUpper(name[sz])) num++;
}
caps=floatdiv(num,strlen(name[0]));//maybe it will work fine if we don't pass floats..?
caps=floatmul(caps,100);
//caps=(num/(strlen(name[0])-1));
printf("%f!!\n",caps);
if(caps>40) return 1; 
return 0;
}
CHC is offline   Reply With Quote
Old 30/01/2010, 07:37 PM   #2
CHC
Little Clucker
 
Join Date: Sep 2009
Posts: 6
Reputation: 4
Default Re: New to pawn, trying to convert some C code to pawn

so...anyone?
CHC is offline   Reply With Quote
Old 22/06/2012, 05:09 AM   #3
Dubya
Huge Clucker
 
Dubya's Avatar
 
Join Date: Jun 2012
Location: Missouri, USA
Posts: 468
Reputation: 33
Default Re: New to pawn, trying to convert some C code to pawn

Code:
TooManyCaps(name[]) 
{
	new Float:caps,num,sz;
	sz = strlen(name[0]);
	while(sz--) 
	{
		if(CHC_IsUpper(name[sz])) num++;
	}
	caps = floatdiv(num,strlen(name[0]));// You forgot to add spaces. (caps=floatdiv should've been caps = floatdiv, the same with the Line below.
	caps = floatmul(caps,100);
	//caps = (num/(strlen(name[0])-1));
	printf("%f!!\n",caps);
	if(caps>40) return 1; 
	return 0;
}
__________________
Dubya is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to convert pawn script file to AMX can u give me the software? Reginald Scripting Help 15 02/01/2018 02:08 PM
Unreachable code - PAWN bug - pragma? Lazarus Help Archive 30 14/06/2011 09:41 AM
PAWN code parser Torekk Everything and Nothing 1 10/10/2010 09:39 PM
MTA map [pick-up convert to Pawn]? Andy_McKinley Help Archive 3 07/03/2010 01:48 PM


All times are GMT. The time now is 08:25 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.