0

I've run into a problem on credit. Whenever I run this

#include <stdio.h>
#include <cs50.h>

int main(void)
{
    int credit;

    //Ask user for input of cc number

    printf("What is your creditcard number?");
    credit = get_long_long();

    //See if number is long enough
    if ( int credit > 100000000000 && int credit < 10000000000000000 ) {
        printf("Hallelujah\n");
    }
    else {
        printf("Nope\n");
    }

}

block of code I get the error:

creditcard.c:14:10: error: expected expression
    if ( int credit > 100000000000 && int credit < 10000000000000000 ) {
         ^
1 error generated.
make: *** [creditcard] Error 1

I checked other questions discussing the same error message, none seem to help me with mine though.

0
if ( int credit > 100000000000 && int credit < 10000000000000000 ) 

When we declare int credit again, within IF, we are really declaring a new variable, different from the first credit outside and with a scope only within the IF block, the solution would be to eliminate the int. But I have to tell you that this will not solve your problems, values to which perform comparison is outside the range that can be stored in an integer. You can check this by simply changing your numbers to smaller ones, such as 10 and 100

3
  • So there's no real solution to my problem?
    – Tom Meier
    Nov 5 '17 at 20:24
  • Actually I have not done this problem, but it seems that you have an alternative in the arrays, it seems a way that should be explored
    – MARS
    Nov 5 '17 at 20:35
  • The solution is somewhat hidden in @MARS answer, the solution would be to eliminate the int (within the condition). This gets you around the error. On 64 bit machines, int usually is same as long long int and large enough to hold a 16 digit credit card number, so even though I don't like it, it is a viable option to use integers (maybe with explicitly using long long int credit;, as int is only guaranteed to be at least 16 bits, while 16 decimal digits require 54 bits at least, and a long long int is guaranteed to have at least 64).
    – Blauelf
    Nov 6 '17 at 13:20

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .