0

I am getting a error in the following line

long checksum = (long) for (int i=1; i < 8; i=i+2)
        {
           if (checksum > 9)
           {
           (((long) 2*(credit_number % (long) pow (10, i+1) - credit_number % (long) pow (10, i))/(long) pow (10 , i) + (credit_number % (long) pow (10, i) - credit_number % (long) pow (10, i-1))/(long) pow (10 , i)) % 10) + 1  
           }
           else
           {
               ((long) 2*(credit_number % (long) pow (10, i+1) - credit_number % (long) pow (10, i))/(long) pow (10 , i) + (credit_number % (long) pow (10, i) - credit_number % (long) pow (10, i-1))/(long) pow (10 , i))
           }
        };

I suspect maybe the entire code might be needed so I am pasting that as well

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

int main (void)
{
    long credit_number;
do
{
    credit_number = get_long("Number: ");
}
while (credit_number < 0);

 long checksum = (long) for (int i=1; i < 8; i=i+2)
        {
           if (checksum > 9)
           {
           (((long) 2*(credit_number % (long) pow (10, i+1) - credit_number % (long) pow (10, i))/(long) pow (10 , i) + (credit_number % (long) pow (10, i) - credit_number % (long) pow (10, i-1))/(long) pow (10 , i)) % 10) + 1  
           }
           else
           {
               ((long) 2*(credit_number % (long) pow (10, i+1) - credit_number % (long) pow (10, i))/(long) pow (10 , i) + (credit_number % (long) pow (10, i) - credit_number % (long) pow (10, i-1))/(long) pow (10 , i))
           }
        };
if ((credit_number >= 340000000000000 && credit_number < 35000000000000) || (credit_number >= 370000000000000 && credit_number < 38000000000000))
{
    if (checksum % 10 == 0)
    {
       printf("AMEX");
    }
    
    else
    {
        printf("INVALID");
    }
}
else
{
    printf("INVALID");
}
}

The error is -

 credit.c:14:18: error: expected expression
 long checksum = for (int i=1; i < 8; i=i+2)
                 ^
1 error generated.
<builtin>: recipe for target 'credit' failed
make: *** [credit] Error 1

I am unable to understand what's wrong with the line of code. Can someone help me with this

1 Answer 1

1

Simple. A "for" statement cannot be used as the object of an assignment statement. x = for(...) just isn't allowed. A for statement does not return a value. It isn't a function call. I'm not even sure what the code is trying to do there.

Going further, there are additional errors inside the for loop. The code is doing big calculations but not assigning the results to any variable.

If this answers your question, please click on the check mark to accept. Let's keep up on forum maintenance. ;-)

1

You must log in to answer this question.

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