Multiplication -
Isolated - 08.08.2016
Hello,
I'm designing a system and have got myself stuck.
Basically, what I'm trying to figure out is this:
If I have a 15-digit string of numbers for example:
How do I multiply every other number by 2? To add to this, how would I then check the result, and if the result per number is a 2-digit number, add the digits together to make it a single digit number?
I've tried using loops, and other methods but all without any luck.
My mathematics skills aren't very good.
I hope this makes sense.
Thank you,
Isolated.
Re: Multiplication -
Sew_Sumi - 08.08.2016
What?
So you're wanting to go...
PHP код:
1*2 , 4*2 , 9*2 , 6*2 , 5*2 , 5*2 , 8*2 , e.t.c.?
or are you meaning (by other number)
PHP код:
1*2 , 9*2 , 5*2 , 8*2 , e.t.c.
Are you sure you need to do it this way? Seems REAL random. Like, I've never seen anyone ask this sort of thing before.
Re: Multiplication -
Isolated - 09.08.2016
Basically, take the first four digits for example:
1*2, 9*2, etc..
So starting at 1, multiply every other number by 2, but, if like 9*2 it's a 2-digit number, like 18, you'd do 1+8 to make a single digit number(9).
The mathematics is simple enough, just converting it to pawn. A way I thought of would be to offset the array?
Re: Multiplication - justice96 - 09.08.2016
It's the way you mean bro?
Код:
new level = Isolated[lol][Multiplication];
((level+1)*2)
Re: Multiplication -
Luicy. - 09.08.2016
PHP код:
new string[15];
format(string, 15, "%i", strval(THE DIGIT INT));
for(new digit = 0; digit < 16; digit += 2) {
//this loops 2 4 6 8 10 12 14
new tempId = strval(string[digit+1])*2;
format(string[digit+1], 1, "%i", tempId);
}
THE DIGIT INT = strval(string);
edit; not sure IF this works or not, Im on phone
Re: Multiplication -
Shinja - 09.08.2016
I still don't get it, show us what will happen to your example number in details
Re: Multiplication -
GunZsmd - 09.08.2016
I dont think what u want to do is possible in pawno... If it is many people wouldnt know it because thats a very weird request and i keep asking myself what u want that math for...
Re: Multiplication -
GunZsmd - 09.08.2016
Quote:
Originally Posted by Shinja
I still don't get it, show us what will happen to your example number in details
|
He wants to pick every every 2 numbers and leave 1 empty like:
149655893228335
||
\/
1*4 6*5 8*9 etc...
And then he wants to find if those numbers are superior to 10 and if they are just add them. Example:
PHP код:
new i = 6*5;
if(i > 10)
{
//the result of the multiplication is 30 so he wants to add 3+0 but idk how to separate those 2 numbers //automatically on pawno or know if it is possible.
}
Re: Multiplication -
Isolated - 09.08.2016
Thank you everyone, I have found a solution. Let me clean it up and I'll post it.
Re: Multiplication -
SickAttack - 09.08.2016
pawn Код:
// ** INCLUDES
#include <a_samp>
// ** MAIN
main()
{
print("Loaded \"multiply_by_2_if_2_digits_add.amx\".");
new array[] = {1, 4, 6, 9}, temp[2], value[2], result[sizeof(array)];
for(new i = 0, j = sizeof(array); i < j; i ++)
{
result[i] = array[i] * 2;
if(result[i] >= 10)
{
valstr(temp, result[i]);
value[1] = strval(temp[1]);
strdel(temp, 1, 2);
value[0] = strval(temp[0]);
result[i] = value[0] + value[1];
}
}
for(new i = 0, j = sizeof(result); i < j; i ++)
{
printf("%d", result[i]);
}
}
// ** CALLBACKS
public OnGameModeInit()
{
return 1;
}
public OnGameModeExit()
{
return 1;
}