I need help writing a c program for credit card validation. Here are the directi
ID: 3733551 • Letter: I
Question
I need help writing a c program for credit card validation. Here are the directions I was given:
The function's inputs are the credit card number and the digit number that needs to be stripped off. It will return the number that is in that digit.
The function "thisOdd" will receive an integer and return back a 1 if it is odd, and a 0 if it is even.
The function "splits" will receive an integer and return back the number in the tens place.
The function "splitOnes" will receive an integer and return back the number in the one's place. It will use the "splitTens" function to accomplish this.
here is my code so far:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int stripper(long long longNumber, int digitNumber) {
return ((longNumber - ((long long)(longNumber / pow(10, digitNumber))*pow(10, digitNumber))) / pow(10, digitNumber - 1));
}
int main()
{
long long testNumber = 5120415296389632; //long long is a data type for a large integer
getchar();
return 0;
}
Explanation / Answer
You can proceed in the following way:
int thisOdd (long int digit)
{
if (digit%2 == 0)
return 0;
else
return 1;
}
This can be a generalized split function which can split any position
int splits(int number, int position)
{
return (number / ((int) pow(10, position)) % 10);
// where position means the ones, tens, hundreds, etc, so it will take value 1,2,3,..
}
If you want two separate functions for splitting, simply rewrite the code once with position 2 (for tens) and again with position 1(for ones)
Call your stripper() from main. Pass the value that it returns to the other two functions.
HOPE THAT HELPS!!