0

Thank you for the answers. I think that I made some steps. The problem now is that I can't store the seperated digits. It only stores the last one in "remain". My other challenge is that seperating the digits above 9 gives the result "0" but i think that is related to the "remain" problem. This is what i have so far.

Some tips or advice would be handy. Thank you in advanced.

//Get creditcard number
do
    {
        credit = get_long("Number: ");
    }    
while (credit < 0);

//Select every other digit starting with number'second to last digit.
tempa = credit;
tempa = tempa /10;
    while (tempa > 0)
    {
        remain = tempa % 10;
// test outcome of remain
        printf("%li\n", remain);
        sumc = sumc + remain; 
        tempa = tempa /100;
    } 
//test outcome of suma
        { 
            printf("sumc: %li\n", sumc);
        }
// Multiply every other digit with 2
remain = remain *2;
//test for multiply
        {
            printf("Remain: %li\n", remain);
        }
// split the digits above 9 in two seperated digits
    for (remain = 0; remain > 9; remain++)
       if
        {
            new_sum = remain % 10;
            r = remain + new_sum;
            new_sum = new_sum / 10;
        }
         else // ????
//test outcome of r
            { 
                printf("r: %li\n", r);
            }
// print the sum of the products
outcome = sumc + r;
            { 
                printf("Outcome: %li\n", outcome);
            }
0

There are two ways to do it: the easier way would be to simply store a variable, say total, and keep adding the digits to it in the loop. The other (and more complicated) way would be to make an array of digits and keep filling it in as you go, which is harder because you do not know how many digits there will be. You aren't introduced to arrays until next week in the course, so the best way is to simply keep adding the digits as you go, and then outside the loop, multiply that variable by two.

0

The first step is to multiply every other number by 2, use a loop so you can multiply the digits and add an if statement that checks if the digits that were multiplied are greater than 9, if that is true you then use the modulo operator to access the ones digit then divide it by 10 then add the two together.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .