I’m working on cs50 and I’m getting this error when trying to run. The program asks the user for a credit card number and then reports (via printf) whether it is a valid American Express, MasterCard, or Visa card number, using luhns algorithm and the requirements for each card. source code is below
#include <stdio.h>
#include <cs50.h>
bool validation(long number) {
int i = 10;
int j = 1;
int totalMultiplied = 0;
int totalNotMultiplied = 0;
while (number / i != 0){
totalMultiplied += ((number / i) % 10) * 2;
i *= 100;
}
while (number / j != 0) {
totalNotMultiplied += (number / j) % 10;
j *= 100;
}
if ((totalMultiplied + totalNotMultiplied) % 10 == 0) {
return true;
}else {
return false;
}
}
int main(void) {
long creditCardNo;
do {
creditCardNo = get_long("Enter credit card number: ");
}
while (creditCardNo < 0);
int count = 0;
long startNumbers = creditCardNo;
long n = creditCardNo;
do {
n /= 10;
count++;
}
while (n != 0);
while (startNumbers >= 100) {
startNumbers /= 10;
}
if (validation(creditCardNo)) {
if (count == 15 && ( startNumbers == 34 || startNumbers == 35)) {
printf("AMEXn");
}
else if (count == 16 && ( startNumbers == 51 || startNumbers == 52 || startNumbers == 53 || startNumbers == 54 || startNumbers == 55)) {
printf("MASTERCARDn");
}
else if ((count == 13 || count == 14) && ( startNumbers / 10 == 4)) {
printf("VISAn");
}
}else {
printf("INVALIDn");
}
}
I expected the program to print what type of card it was if the card was valid or invalid if the card was invalid
9