error: format specifies type 'long long' but the argument has type 'long long (*)(long long)

Hi, new to C++ but thought i had a good understanding of the basics, however, im having trouble compiling my program.
PLEASE NOTE THAT I ONLY WANT HELP WITH THIS COMPILE ERROR..
any other errors I will TRY to solve myself.. thanks
(I have edited and commented so much of this code just to sole this error, but now I give up)
Help please ;)

cardcheck.c:90:39: error: format specifies type 'long long' but the argument has type 'long long (*)(long long)' [-Werror,-Wformat]
printf("First Digit = %lli\n",firstDigit);
~~~~ ^~~~~~~~~~
cardcheck.c:91:44: error: format specifies type 'long long' but the argument has type 'long long (*)(long long)' [-Werror,-Wformat]
printf("First Two Digits = %lli\n",firstTwoDigits);
~~~~ ^~~~~~~~~~~~~~



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
 #include <stdio.h>
#include <cs50.h>
//#include <string.h>

    // gets the FIRST digit of card number
long long firstDigit(long long cardNumber){
    long long number = cardNumber;
    while (number > 10){
    number = number / 10;
    // printf("currect first digit = %lli\n",number);
    }
    return number;
}

    //gets the first TWO digits of the cardnumber
long long firstTwoDigits(long long cardNumber){
    while (cardNumber > 100){
    cardNumber = cardNumber / 10;
    }
    return cardNumber;
}


int productSum(number){

    int y = 0;
    while (number>0){
   
    //Add last digit to y
    y = y + number % 10;
    
    //Remove last digit
    number = number / 10;
    
    }
    return y;
 }   


int checkSum(long long checkNumber){

    int x = 0;
    int Xx2 = 0;
    
    while (checkNumber > 0){
    //Add last digit to x
    x = x + (checkNumber % 10);
    
    //Remove last digit
    checkNumber = checkNumber / 10;
    
    //multiply the next last digit by 2 the add the product sum to Xx2
    Xx2 = Xx2 + productSum((checkNumber % 10 * 2));
    
    //Remove last digit and repeat
    checkNumber = checkNumber / 10;
    }
    return ((x + Xx2) % 10);  
}


int main(void)
{


//get input from user
    printf("Give me a card number\n");
    long long inputedCardNumber = GetLongLong();
    
//check if input length is valid
    int cardLength = 0;
    long long cardNumber = inputedCardNumber;
    
    if(checkSum(cardNumber)==0){   
        while(cardNumber > 0){
          cardNumber = cardNumber /10; 
          cardLength = cardLength + 1;
         }
          //Visa   
    if(cardLength == 13 && firstDigit(inputedCardNumber) == 4){
        printf("%lld\nVISA\n",inputedCardNumber);
     }
      else if(cardLength== 15 && firstTwoDigits(inputedCardNumber) == 37){
             printf("%lld\nAMERICAN EXPRESS\n",inputedCardNumber);
             } 
             
             
        else {
        printf("Card Length = %i\n",cardLength);
        printf("First Digit = %lli\n",firstDigit);
        printf("First Two Digits = %lli\n",firstTwoDigits);
        printf("Invalid \n");
        }
     }
        return 0;
}
        
 /*  
    //American Express
    
        
    //MasterCard or Visa
             if (cardLength== 16){
            if (firstTwoDigits(cardNumber) >50 && firstTwoDigits(cardNumber)<56){
        //MasterCard
           printf("\nMASTERCARD");
         }else{
            if(firstDigit(inputedCardNumber)==4){
     //VISA
         printf("%lld VISA\n",inputedCardNumber);
         }
     } 
   }
   }
         printf("card length = %i\n",cardLength);
         printf("first digit = %lld\n",firstDigit(inputedCardNumber));


*/
Last edited on
printf("First Digit = %lli\n",firstDigit);
printf("First Two Digits = %lli\n",firstTwoDigits);

firstDigit and firstTwoDigits are functions. You can't just print functions.
Thanks for that, I have adopted my code to solve that problem.

however, im still at a loss as to why my 2 SIMPLE functions are not giving my my intended results.
More help with this would be appreciated.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#include <stdio.h>
#include <cs50.h>
//#include <string.h>

    // gets the FIRST digit of card number
long long firstDigit(x){ 
    while (x > 10){
    x = x / 10;
    }
    return x;
}

    //gets the first TWO digits of the cardnumber
long long firstTwoDigits(x){
    while (x > 100){
    x = x / 10;
    }
    return x;
}


int productSum(number){

    int y = 0;
    while (number>0){
   
    //Add last digit to y
    y = y + number % 10;
    
    //Remove last digit
    number = number / 10;
    
    }
    return y;
 }   


int checkSum(checkNumber){

    int x = 0;
    int Xx2 = 0;
    
    while (checkNumber > 0){
    //Add last digit to x
    x = x + (checkNumber % 10);
    
    //Remove last digit
    checkNumber = checkNumber / 10;
    
    //multiply the next last digit by 2 the add the product sum to Xx2
    Xx2 = Xx2 + productSum((checkNumber % 10 * 2));
    
    //Remove last digit and repeat
    checkNumber = checkNumber / 10;
    }
    return ((x + Xx2) % 10);  
}


int main(void)
{


//get input from user
    printf("Give me a card number\n");
    long long inputedCardNumber = GetLongLong();
    
//check if input length is valid
    int cardLength = 0;
    long long cardNumber = inputedCardNumber;
    
    if(checkSum(cardNumber)==0){   
        while(cardNumber > 0){
          cardNumber = cardNumber /10; 
          cardLength = cardLength + 1;
         }
          //Visa   
    if(cardLength == 13 && firstDigit(inputedCardNumber) == 4){
        printf("%lld\nVISA\n",inputedCardNumber);
     }
      else if(cardLength== 15 && firstTwoDigits(inputedCardNumber) == 37){
             printf("%lld\nAMERICAN EXPRESS\n",inputedCardNumber);
             } 
             
             
        else {
        long long x = firstDigit(inputedCardNumber);
        long long y = firstTwoDigits(inputedCardNumber);
        printf("Card Length = %i\n",cardLength);
        printf("First Digit = %lli\n",x);
        printf("First Two Digits = %lli\n",y);
        printf("Inputed card number = %lli\n",inputedCardNumber);
        printf("Invalid \n");
        }
     }
        return 0;
}


RESULT=
Give me a card number
378282246310005
Card Length = 15
First Digit = -1293252491
First Two Digits = -1293252491

Inputed card number = 378282246310005
Invalid
long long firstDigit(x){ Is this exact code you have? Because you are missing type specifier there and if you have ancient C compiler, implicit int rule applies, so you are trying to pass long long variable in int and overflow happens.
Thanks loads, I have changed it to
long long firstDigit(long long x){
And finaly it works.

Thanks again.. ;)
Topic archived. No new replies allowed.