+ 2

why is My last two test fails

Am working on my code coch challange "credit card validator " my last 2 test result fails .. can't figure it out why.. Anyone please point out why.. [Code objective: check validity Input : 16digit number Output : "valid" or "not valid" Rules to check validity : given in the code as comment ] https://code.sololearn.com/cc8bf0WJ8o30/?ref=app

8th Oct 2023, 6:02 PM
MOHAMMED SHAHUL
MOHAMMED SHAHUL - avatar
11 Respostas
+ 4
GAME PRO , the issue is definitely the missing check for the length of the input number. we do not have to care about other kind of characters, since these are not used in the test cases. all the other calculations in the code are working properly. but >>> pay attention to how to get this number. `reversed_digit` is an array for 16 int numbers. so if you check this array for length, you may get always 16 as a result, regardless how many digits the input have. the condition of the while loop at the beginning of the code should be modified like: while (n > 0){ digit = n % 10; n = n /10; reverse_digit [j] = digit; j++; arr_len = j; after the loop is done, `arr_len` shows the correct length that can be used to verify the correct length: if (sum % 10 == 0 && arr_len == 16) { …
8th Oct 2023, 9:49 PM
Lothar
Lothar - avatar
+ 3
Sorry .. I corrected it...
10th Oct 2023, 11:33 AM
MOHAMMED SHAHUL
MOHAMMED SHAHUL - avatar
+ 2
Thanks guys ...I got the it right ..
9th Oct 2023, 5:51 PM
MOHAMMED SHAHUL
MOHAMMED SHAHUL - avatar
+ 1
I took a look at my own solution I made long time ago in C, and I can see that you don't have a condition to check that the input is 16 characters long and only contains numbers from 0 to 9, but I also used string as input type. I think you should rewrite the code and use string as input instead, and then create the necessary conditions.
8th Oct 2023, 7:24 PM
Jan
Jan - avatar
+ 1
I recheck and made some modifications. Which is if wr enter 16 digit .. the code will work as usual. And if enter morethan 16 digit then it will eliminate the extra. And do as before.. https://code.sololearn.com/ckmxiqufpx1D/?ref=app
9th Oct 2023, 12:31 PM
MOHAMMED SHAHUL
MOHAMMED SHAHUL - avatar
+ 1
Quantum I checked it . I couldn't find any flow like that.
10th Oct 2023, 10:25 AM
MOHAMMED SHAHUL
MOHAMMED SHAHUL - avatar
0
I don't know what the locked test cases are looking for, but I can enter any number of letters as input in your code and it returns "valid". Maybe at least one of those cases is checking for anything other than integers?
8th Oct 2023, 7:00 PM
Aaron Lee
Aaron Lee - avatar
0
GAME PRO There is a huge flaw in your program, because if I enter a letter like a, it then says valid. I wonder why the test cases accept that. The test cases seem not to check on letters. That's weird.
9th Oct 2023, 9:04 PM
Jan
Jan - avatar
0
Try new code to unique
10th Oct 2023, 6:58 AM
SHIVANAND KUMAR
SHIVANAND KUMAR - avatar
0
GAME PRO But it still says valid if you enter a letter as input.
10th Oct 2023, 10:51 AM
Jan
Jan - avatar
0
That's better now.
10th Oct 2023, 12:00 PM
Jan
Jan - avatar