What is the issue with this code in C of adding every other number?

By code1993

#include <stdio.h>
int main(void)
{
  long long orig_num;
  int even = 0;
  int a = 0;
  do
  {
    printf("Enter CC number: ");
    scanf("%lli", &orig_num);
    if(orig_num<0)
    {
      printf("Invalid Number. ");
    }
  }
  while (orig_num<0);
  while(orig_num!=0)
  {
    orig_num = orig_num/10;
    int temp = orig_num%10;
    if((temp*2) >= 10)
    {
      int t = temp*2;
      temp=temp*2;
      temp = temp%10;
      even += temp;
      t = t/10;
      even+= t;
    }
    else
    {
      temp = temp*2;
      even += temp;
    }
    orig_num = orig_num/10;
  }
  printf("The addition for the even numbers were: %dn", even);
}

This code is working for most part, but I am running into a couple issues where if it recognizes the number 0 it will give a weird number, and it also gives a wrong output if it recognizes a 1, what it does it actually add 1+1 instead of multiplying, and I do not know what exactly is what I am doing wrong. This code is supposed to get every other number a add them but if the number that is being multiplies is greater than 0 then just add the two integers, example 6*6=12 12>10, so 1+2=3. Please help. Thank you!

Source: Stack Overflow

    

Share it with your friends!

    Fatal error: Uncaught Exception: 12: REST API is deprecated for versions v2.1 and higher (12) thrown in /home/content/19/9652219/html/wp-content/plugins/seo-facebook-comments/facebook/base_facebook.php on line 1273