-
Cleaner Code
I have a code that consolidates current moneys into the least amount of tokens possible. It works but the actual code is extremely bulky, i was wondering if anyone has a tip or sees something that can be removed/replaced for less code
Thanks
code: C_Amount = _root.betTotal;
if(C_Amount < 25)
{
NumLeft = C_Amount % 10;
if(NumLeft < 5)
{
dollar_1 = NumLeft;
dollar_10 = (C_Amount - NumLeft) / 10;
}else{
NumLeft1 = NumLeft % 5;
dollar_1 = NumLeft1;
dollar_5 = (NumLeft - NumLeft1) / 5;
dollar_10 = (C_Amount - NumLeft) / 10;
}
}
-
I am kinda nooby and this is really the best way I know how to do this. I started adding the next half and this just got too confusing, I need an different cleaner way of doing this, since much of this is recursive I could do that but I am not sure how cuz it is a little different each time the amount gets higher and higher. This works but its really not useable because i need to do it about 3 more times
code: //Gets amount of chips every round
C_Amount = _root.betTotal;
if(C_Amount < 25)
{
NumLeft = C_Amount % 10;
if(NumLeft < 5)
{
dollar_1 = NumLeft;
dollar_10 = (C_Amount - NumLeft) / 10;
}else{
NumLeft1 = NumLeft % 5;
dollar_1 = NumLeft1;
dollar_5 = (NumLeft - NumLeft1) / 5;
dollar_10 = (C_Amount - NumLeft) / 10;
}
} else if(C_Amount < 100)
{
NumLeft = C_Amount % 25;
if(NumLeft < 10)
{
if(NumLeft < 5)
{
dollar_1 = NumLeft;
dollar_5 = 0;
dollar_10 = 0;
dollar_25 = (C_Amount - NumLeft) / 25;
}else{
NumLeft1 = NumLeft % 5;
dollar_1 = NumLeft1;
dollar_5 = (NumLeft - NumLeft1) / 5;
dollar_10 = 0;
dollar_25 = (C_Amount - NumLeft) / 25;
}
} else {
NumLeft1 = NumLeft % 10;
if(NumLeft1 <= 5)
{
if((NumLeft1 % 5) >= 0)
{
dollar_1 = NumLeft1;
dollar_5 = 0;
} else {
dollar_5 = 1;
dollar_1 = 0;
}
dollar_10 = (NumLeft - NumLeft1) / 10;
dollar_25 = (C_Amount - NumLeft) / 25;
}else{
NumLeft2 = NumLeft1 % 5;
dollar_1 = NumLeft2;
dollar_10 = (NumLeft - NumLeft1) /10;
dollar_5 = (NumLeft1 - NumLeft2) / 5;
dollar_25 = (C_Amount - NumLeft) / 25;
}
}
}
trace(dollar_1);
trace(dollar_5);
trace(dollar_10);
trace(dollar_25);
Last edited by JBS103; 10-03-2004 at 05:01 AM.
-
theres gotta be a way
-
im sorry im being naggy but the code will be soooo long if I continue to do what I am doing. I know there has to be a shorter way
-
what are the smallest tokens?
smallest tokens
If you had 10 dollars, it would be shown as 1x10?
If you had 1,30 it would be shown as (1x1) + (3x10)?
What are the "smallest" tokens? Try something with Math.round
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|