Skip to main content
added 7 characters in body
Source Link
Cliff B
  • 69.3k
  • 4
  • 33
  • 56

Of course it's moving past the while loop. It's just not doing anything that you see before it terminates. Try inputting a 3 digit number and see what it does.

The actual problem is here:

if (digits == 13 || digits == 15 || digits == 16) {
   return digits;
}

A return statement in main will immediately terminate the program. If it has a value or variable in the statement, it will return that value to the operating system. This code is returning any cc number length stored in digits that is 13, 15, or 16. If the length of the cc numberlength is anything else, it'll run the code that follows.

If this answers your question, please click on the check mark to accept. Let's keep up on forum maintenance. ;-)

Of course it's moving past the while loop. It's just not doing anything that you see before it terminates. Try inputting a 3 digit number and see what it does.

The actual problem is here:

if (digits == 13 || digits == 15 || digits == 16) {
   return digits;
}

A return statement in main will immediately terminate the program. If it has a value or variable in the statement, it will return that value to the operating system. This code is returning any cc number stored in digits that is 13, 15, or 16. If the length of the cc number is anything else, it'll run the code that follows.

If this answers your question, please click on the check mark to accept. Let's keep up on forum maintenance. ;-)

Of course it's moving past the while loop. It's just not doing anything that you see before it terminates. Try inputting a 3 digit number and see what it does.

The actual problem is here:

if (digits == 13 || digits == 15 || digits == 16) {
   return digits;
}

A return statement in main will immediately terminate the program. If it has a value or variable in the statement, it will return that value to the operating system. This code is returning any cc number length stored in digits that is 13, 15, or 16. If the length of the cc length is anything else, it'll run the code that follows.

If this answers your question, please click on the check mark to accept. Let's keep up on forum maintenance. ;-)

Source Link
Cliff B
  • 69.3k
  • 4
  • 33
  • 56

Of course it's moving past the while loop. It's just not doing anything that you see before it terminates. Try inputting a 3 digit number and see what it does.

The actual problem is here:

if (digits == 13 || digits == 15 || digits == 16) {
   return digits;
}

A return statement in main will immediately terminate the program. If it has a value or variable in the statement, it will return that value to the operating system. This code is returning any cc number stored in digits that is 13, 15, or 16. If the length of the cc number is anything else, it'll run the code that follows.

If this answers your question, please click on the check mark to accept. Let's keep up on forum maintenance. ;-)