# Dealing with pset1's "credit" problem

I was trying to solve this problem. I did some coding:

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

int get_digit_number(long card_number);

int main(void){

bool valid;
long card = get_long("Enter card number: ");
long card2 = card / 10;
long card3 = card;
int digit_number = get_digit_number(card);
if (digit_number != 13 || digit_number != 15 || digit_number != 16)
{
valid = false;
printf("INVALID");
}

int digits1 = 0;
int digits2 = 0;
int sum1 = 0;
int sum2 = 0;
int card_brand;

for(int i = 0; i <= digit_number; i + 2)
{
//first sum
digits1 = card3 % 10;
card3 /= 100;
sum1 += digits1;

//second sum
digits2 = card2 % 10;
digits2 *= 2;
if (digits2 >= 10)
{
sum2 = digits2 % 10;
digits2 -= digits2 % 10;
digits2 /= 10;
sum2 += digits2;
}
else{
sum2 += digits2;
}
card2 /= 100;
}

for (int k = 0; k < digit_number - 2; k++)
{
card_brand = card / 10;
}

if ((sum1 + sum2) % 10 != 0)
{
valid = false;
printf("INVALID\n");
}
else {
valid = true;
printf("VALID\n");
}

if (valid && (((card_brand - (card_brand % 10)) / 10  == 4)))
{
printf("VISA\n");
}
else if (valid && (card_brand > 50 && card_brand < 56))
{
printf("MASTERCARD\n");
}
else if (valid && (card_brand == 34 || card_brand == 37))
{
printf("AMEX\n");
}
}

int get_digit_number(long card_number)
{
int y = 1;
while (card_number >= 10)
{
card_number /= 10;
y++;
}
return y;
}
``````

but when I try to make credit2.c, it gives me two errors:

credit2.c:20:16: error: variables 'i' and 'digit_number' used in loop condition not modified in loop body [-Werror,-Wfor-loop-analysis] for(int i = 0; i <= digit_number; i + 2)

credit2.c:20:37: error: expression result unused [-Werror,-Wunused-value] for(int i = 0; i <= digit_number; i + 2)

What is my problem here? I'm a total noob btw. Thanks in advance.

``````for(int i = 0; i <= digit_number; i + 2)
The increment clause `i + 2` isn't properly written. This takes the value in i and adds it to 2, but it doesn't say where to store the result or what to do with it. This also causes the expression result unused error. Things like `i++` work because the ++ operator automatically stores the result back in i. In this case, the code should store the result back in i, like this: `i = i + 2`.