number = get_long_long("What is your credit card number? ");
while((number < 1000000000000) || (number >= 10000000000000000));

This loop is not accepting inputs. I do not understand why.

I've tried the numbers: 4111111111111113, 4222222222223, 5673598276138003. Same result - the "do" keeps looping infinitely. What is going on?

  • There is no get_long_long function in the current cs50.h, it was deprecated c. 2019. Make sure to be using the current versions esp. if you're working towards a grade. Feb 1 '21 at 20:12
  • What function should I use then? get_long? Just followed that link - it appears that actually get_long_long is active in the "less comfortable" challenges. "get_long_long - prompts user for a line of text from stdin and returns the equivalent long long" Feb 1 '21 at 20:45
  • I see that (it is displayed with "less comfortable" turned off). I tried this function in the IDE with long long number; declaration. It worked with all the sample inputs Feb 2 '21 at 1:09
  • Maybe my IDE is bugged? It simply is not accepting certain values in a seemingly random way. Feb 2 '21 at 11:22
  • It seems unlikely that the IDE is bugged (but never out of the question :). "not accepting certain values in a seemingly random way" sounds like "unpredictable results" which sounds like a memory issue. Perhaps the complete code would elucidate. Feb 2 '21 at 19:58

First of all, there is no get_long_long in the cs50.h library. https://manual.cs50.io/

Secondly, this is a clunky way to limit your input that most probably is causing some of your issues.

A more elegant way is to use the while loop to make sure it is a positive input and then calculate the length of your number by using a remainder.

    number = get_long("What is your credit card number? ");

while (number < 0); 

int count = 0;

while (number != 0)
    number /= 10;

Count will now detect the length of your cc number and you can evaluate wether it is a Visa, Mastercard, Amex or invalid input via a simple if check.

Just make sure to create a duplicate (buffer) of your cc number so you don't loose the original input.

  • get_long_long does exist in cs50.h. You just need to turn off the "less comfortable" toggle at the top of the page. Mar 29 '21 at 19:06
  • Thanks for the hint Rob !
    – Joesns
    Mar 29 '21 at 19:10

You must log in to answer this question.

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