Multiplication
#1

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:
Код:
149655893228335
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.
Reply
#2

What?


So you're wanting to go...


PHP код:
1*4*9*6*5*5*8*e.t.c.? 
or are you meaning (by other number)

PHP код:
1*9*5*8*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.
Reply
#3

Basically, take the first four digits for example:

Код:
1 4 9 6
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?
Reply
#4

It's the way you mean bro?

Код:
new level = Isolated[lol][Multiplication];

((level+1)*2)
Reply
#5

PHP код:
new string[15];
format(string15"%i"strval(THE DIGIT INT));
for(new 
digit 0digit 16digit += 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
Reply
#6

I still don't get it, show us what will happen to your example number in details
Reply
#7

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...
Reply
#8

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 6*5;
if(
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.

Reply
#9

Thank you everyone, I have found a solution. Let me clean it up and I'll post it.
Reply
#10

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;
}
pawn Код:
2
8
3
9
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)