Why won't this code print every other digit in a long long number (in this case, it's suppposed to be a credit card number), and add these numbers up? You'll notice I commented out several lines of code, but some lines are actual comments to explain what I mean by the long long odd_group_sum variable. My plan was to calculate the sum of the "odd-numbered positioned" digits in the credit card number first (ie: the number in the first space, then third space, fifth space, etc.) , then after figuring that out, i was going to attempt finding a way to multiply the "even-number positioned digits" by two, and add their digits, and proceed with the code basically. The point of all of this is to code a verifier of authenticity of credit card numbers.
Please excuse my unpleasant-looking code, I'm a beginner just learning :)
(in the commented out lines, you'll see I have variables for specific positions of the digits, and I was going to try to do the code the long way without abstracting the process, thinking there was no short way, but then I thought maybe I can do this in a shorter way, and I got stuck.)
Thank you!
#include <stdio.h>
#include <cs50.h>
int main(void)
{
long long cc_number;
do
{
cc_number = get_long_long ("Please enter a credit card number: ");
}
while (cc_number <= 0 );
//long long first_digit;
//long long third_digit;
//long long fifth_digit;
//long long seventh_digit;
//long long ninth_digit;
//long long eleventh_digit;
//long long thiteenth_digit;
//long long fifteenth_digit;
// the following long_long variable is for the sum of the digits that
//start with the last digit, skip one, then third digit, and so
// on, so it is the sum of the digits that are in the "odd number
positions". eg: position 1, 3, 5, etc., with last digit being
//position 1.
//long long odd_group_sum = 0;
long long digit = 0;
long long previous_sum = 0;
while (cc_number >1);
{
printf("%lld\n", cc_number%10);
scanf ("%lld", &digit);
printf("Sum so far of %lld plus %lld is %lld", previous_sum,
digit, previous_sum + digit);
scanf("%lld", &previous_sum);
cc_number / 100;
}
}