Untitled

 avatar
unknown
plain_text
4 years ago
1.4 kB
1
Indexable
#include<cs50.h>
#include<stdio.h>

void number_of_digits(void);

int main(void)
{
   long visa_card_number;
   visa_card_number = get_long("please enter your credit card number: ");

   //counting the length of the credit card number

     long i = visa_card_number;
   int cc = 0;
   do
   {
     i = i / 10;
     cc++;
   }
   while( i > 0);


   //valdating credit card number


   long x =  visa_card_number;
   int d1;
   int d2;
   int d3;
   int d4;
   int d5;
   int d6;
   int d7;
   int d8;
   int sum1=0;

     d1 = (((x/10) % 10) * 2);
     d2 = (((x / 1000) % 10) * 2);
     d3 = (((x / 100000) % 10) * 2);
     d4 = (((x / 10000000) % 10) * 2);
     d5 = (((x / 1000000000) % 10) * 2);
     d6 = (((x / 100000000000) % 10) * 2);
     d7 = (((x / 10000000000000) % 10) * 2);
     d8 = (((x / 1000000000000000) % 10) * 2);
      
      int n1 = (x % 10);
      int n2 = ((x / 100) % 10);
      int n3 = ((x / 10000) % 10);
      int n4 = ((x / 1000000) % 10);
      int n5 = ((x / 100000000) % 10);
      int n6 = ((x / 10000000000) % 10);
      int n7 = ((x / 1000000000000) % 10);
      int n8 = ((x / 100000000000000) % 10);
      int sum2 = 0;
      int total;

   if(cc == 16 )
   {
       sum1 = d1 + d2 + d3 + d4 + d5 + d6 + d7 + d8;
       sum2 = n1 + n2 + n3 + n4 + n5 + n6 + n7 + n8;
       total = sum1 + sum2;
       if(total % 10 ==0)
       {
           printf("visa");
       }
   }




}



Editor is loading...