0
#include <stdio.h>
#include <cs50.h>
int main(void)
{
long creditcardno;
do
{
    creditcardno = get_long("enter");
}
while (creditcardno < 1000000000000 || creditcardno > 9999999999999999);
int i = 0;
long cc = creditcardno;
while (cc > 0)
{
    cc = creditcardno / 10;
    i++;
}
printf("%d", i);

}

After accepting the input of number between 1000000000000 and 9999999999999999, the program seems get into some kind of infinite loop.

enter image description here I expect to print the number of digits of the entered credit card no.

2 Answers 2

1

This while (cc > 0) is an infinite loop because neither the value of cc nor creditcardno changes, therefore cc is always > 0.

0
0

By replacing creditcardno with cc, the objective is met.

while (cc > 0)
{
    cc = cc / 10;
    i++;
}
printf("%d", i);

You must log in to answer this question.

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