0

I've been trying to figure out what's wrong with my code. I used printf so I could confirm whether or not the value of N is correct but it's coming out as completely different as what I would expect it to. Please tell me what I'm doing wrong so I can fix it.

#include <cs50.h>
#include <stdio.h>
int main(void)
{
// Prompt user to input card number
long cardNumber, N;
int v = 0, d;

do
{
    cardNumber = get_long("Card Number: ");
}
while ((cardNumber < (1e12)) || (cardNumber > (1e16)));

// Calculate sum of digits non-underlined digits

N = cardNumber;

while (v < 16)
{
    N = N / 10^v;
    d = N % 10;
    v += 2;
}
printf("%li", N);
}

1 Answer 1

1

It looks like you expect ^ to do exponentiation. It doesn't; it is the Bitwise XOR operator in C. You can use the pow function in the math library instead.

1
  • wow I don't know whether to laugh or cry right now because I've been trying to figure out what I was doing wrong for almost two days now. thank you sooo much !!
    – maira
    Commented Dec 22, 2021 at 18:47

You must log in to answer this question.

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