why is this function going infinite?

4120670000624855 = cardnumber
I expect 23... but going inifinte...
int CardValication2(long long int cardnumber)
{
bool zero = true;
long long int a, total = 0;
do{
cardnumber % 10;
a = cardnumber % 10;
total += a;
cardnumber / 100;
cout << total << endl;
if (cardnumber == 0)
zero = false;
} while (zero);
return total;

}
Becuase of if (cardnumber == 0)

That will never happen.

Edit: yeh read below.

You have to do cardnumber = cardnumber / 100;
Last edited on
Note that cardnumber % 10; and cardnumber / 100; doesn't modify cardnumber. It doesn't really do anything at all.
cardnumber % 10; and cardnumber / 100; do nothing, and your compiler should have warned you too.

You are looking for:
cardnumber = cardnumber % 10;
And the same for the other situation.
Thx you! I realized i did it on other function but not this function.
Hey, If you ever need help again and post on this forum, please put your code between code tags under the format section - http://www.cplusplus.com/articles/jEywvCM9/

Will be much easier to help you :)
Topic archived. No new replies allowed.