Excuse my not so concise code, but I wrote this method, and I get three errors. The first one is when I declare int k=0; it says expresion expected and points to int. Two later errors are that k is undeclared.
The question is: is this the problem with how I initialize k or is it the problem with the code itself?
bool checkSum(long cardNumber, int numberOfDigits){
      char str[250];
      sprintf(str, "%ld", cardNumber);
      printf("%s\n", str);
      switch(numberOfDigits)
      {
          case 13:
              int k = 0;
              int sum=0;
              int sum1=0;
              int finalsum;
              int multiplied;
              int sumOfPartition = 0;
              for(int i = 0; i<13; i++)
              {
                  k++;
                  if(k%2==0)
                  {
                      char digit = str[13-i];
                      //converting char to int
                      int number = digit - '0';
                      multiplied = number*2;
                      // if multiplied has two digits
                      if(multiplied>9)
                      {
                          char partitioned[2];
                          sprintf(partitioned, "%d", multiplied);
                          int firstDigitOfPartition = partitioned[0]-'0';
                          int secondDigitOfPartition = partitioned[1]-'0';
                          sumOfPartition = firstDigitOfPartition+secondDigitOfPartition;
                          multiplied = 0;
                      }
                  }
                  else
                  {
                      char digit1 = str[13-i];
                      int number1 = digit1-'0';
                      sum1 = sum1 +number1;
                  }
                 sum =  sum + sumOfPartition+multiplied;
                 sumOfPartition = 0;
              }
              finalsum = sum+sum1;
              if(finalsum%10==0)
              {
                  return true;
              } else{
                  return false;
              }
          case 14:
          case 15:
          case 16:
          default:
              printf("heh");
      }
      return true;
  }
