i have written the program for the credit but is not giving the expected output please let me Know if my code requires any change or if the logic is correct or wrong let me know.
here is what i get when executing. make credit clang -fsanitize=signed-integer-overflow -fsanitize=undefined -ggdb3 -O0 -std=c11 -Wall -Werror -Wextra -Wno-sign-compare -Wno-unused-parameter -Wno-unused-variable -Wshadow credit.c -lcrypt -lcs50 -lm -o credit $ ./credit Number: 1000200030004000 INVALID $ ./credit Number: 4000300020001000 INVALID $
here is my program.
include
include
int main(void) { int count=0; long int credit; int sum = 0; int sum1 = 0; int i=0; long int t,s; do { credit = get_long("Number: "); } while(credit < 1);
while((credit%10) > 0)
{
count++;
}
if((count != 15) || (count != 16))
{
printf("INVALID\n");
return 0;
}
else
{
while((((credit % 10) > 0) && (i < 15)) || (i < 16))
{
i++;
if(i%2 != 0)
{
sum = sum + (credit % 10);
}
else
{
t = 2 * (credit % 10);
while(t%10 >= 0){
sum1 = sum1 + (t%10);
}
}
}
s = sum + sum1;
if (s%10 == 0)
{
printf("valid credit %ld\n",s);
}
else
{
printf("invalid credit %ld\n",s);
}
}
} enter code here