# 我无法在C的while循环中找出一些错误。解决cs50积分中的问题：卢恩算法

``````#include <stdio.h>
#include <cs50.h>

int sum_digits(int number2);
int get_number_digits(long x);
int times_two(int x);

int main(void) {

//Prompt for input
long number = get_long("Card Number: \n");
//initialize number to two different variables for [1. multiplying by
//2, adding the products]
//[2. adding every other digit]
long number2 = number;
long number3 = number;

//Calculate checksum

//Multiply digits by 2 alternately starting from the tens place, then
//add the digit of the products NOTE: edit loop, something is wrong
long remainderr2, currentnumber2, product, initialsum, finalfinalsum;
currentnumber2 = number3 / 10;
number3 = currentnumber2;

int finalsum = 0;
while (number3 > 0) {

number3 = currentnumber2;
remainderr2 = currentnumber2 % 10;
product = times_two(remainderr2);
initialsum = sum_digits(product);
finalfinalsum = 0 + finalsum;
finalsum = finalsum + initialsum;
currentnumber2 = currentnumber2 / 10;
currentnumber2 = currentnumber2 / 10;
}
printf("%ld", finalfinalsum);
}

//Function that adds the digits of a number
int sum_digits(int number2) {
int secondstep, remainderr, currentnumber, sum;
currentnumber = number2;
secondstep = 0;
while (number2 > 0) {
number2 = currentnumber;
sum = 0 + secondstep;
remainderr = currentnumber % 10;
secondstep = sum + remainderr;
currentnumber = number2 / 10;

}
return sum;

}

//Function that multiplies int by 2
int times_two(int x) {
x = x * 2;
return x;
}

``````