Can anyone tell me how i messed up the logic here?


Joined
Jul 2, 2022
Messages
1
Reaction score
0
im doing the cs50 course and doing this problem https://cs50.harvard.edu/x/2022/psets/1/credit/

while(cardnumber!=0)
{
digits[noofdigits]=cardnumber%10;
printf("count: %i \n", digits[noofdigits]);
cardnumber=cardnumber/10;
noofdigits++;
}

this is the output thats coming out

Number:12345

count: 5

count: 4

count: 3

count: 3

count: 4

cardnumber%10- should get the last digit onto the array right what's happening here i don't understand
 
Ad

Advertisements

Joined
Jul 4, 2022
Messages
3
Reaction score
0
C:
while(cardnumber!=0)
{
digits[noofdigits]=cardnumber%10;
printf("count: %i \n", digits[noofdigits]);
cardnumber=cardnumber/10;
noofdigits++;
}
cardnumber%10- should get the last digit onto the array
Seems correct to me. Post the complete code and the environment details.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top