+ 1
Credit Card Validator solution please
Please give me the solution code of Credit Card Validator in c language In this program I was able to reverse the string. But I got stuck heređ https://code.sololearn.com/cnDyrR3y8YWW/?ref=app
11 Answers
+ 7
Hello and welcome to sololearn
We can't do work homeworks here so you have to show your attempt so that we may help you :)
What you have to do just paste your code here
https://www.sololearn.com/post/75089/?ref=app
https://www.sololearn.com/discuss/333866/?ref=app
+ 5
Try it yourself. If you'll face any problem there then, we'll help you with that. If you have tried it, show us your code. It's a code coach solution...
Kindly paste your code if you've tried.
+ 5
Tulika Tiwari It's a pro code coach and we are{at least me} not pro member so can't see the code coach description
+ 4
You should try to solve it . If you still find difficulties with that attach your attempt we will try to help you.
+ 4
Coach description:-
Credit Card Validator +50 XP
You need to verify if the given credit card number is valid. For that you need to use the Luhn test.
Here is the Luhn formula:
1. Reverse the number.
2. Multiple every second digit by 2.
3. Subtract 9 from all numbers higher than 9.
4. Add all the digits together.
5. Modulo 10 of that sum should be equal to 0.
Task:
Given a credit card number, validate that it is valid using the Luhn test. Also, all valid cards must have exactly 16 digits.
Input Format:
A string containing the credit card number you need to verify.
Output Format:
A string: 'valid' in case the input is a valid credit card number (passes the Luhn test and is 16 digits long), or 'not valid', if it's not.
Sample Input:
4091131560563988
Sample Output:
valid
+ 3
Added my attempt code
+ 3
Sorry to say, but we don't know C language. You can wait for someone else
+ 3
1st need to convert char string into integer...but how I don't know
+ 2
You may try the function strtol():
value = strtol(string, NULL, 10);
http://www.cplusplus.com/reference/cstdlib/strtol/
Or you may parse the string directly and work with the digits. Take a look at this example here:
https://www.sanfoundry.com/c-program-sum-all-digits-string/
+ 2
This task can be solved with one for loop.
strlen(str) for string length, str[i]-48 to convert char to int
+ 1
It seems you quite don't follow the Luhn formula. Read it carefully again, point by point and break the program in few steps. I may write this program, but it will take some time. đ€