0

It is mentioned in the problem:

American Express uses 15-digit numbers, MasterCard uses 16-digit numbers, and Visa uses 13- and 16-digit numbers.

So with get_long, I perhaps need to restrict input integers by user from 13 to 16 digits.The objective is met for smaller integers such as between 10 and 99.

#include <stdio.h>
#include <cs50.h>
int main(void)
{
int input;
do
    {
      input = get_long("enter");
    }
 while (input<10 || input>99);  

}

Seeking help for ways I can restrict input of integers from 13 to 16 digit numbers. While I can accept input from 10 to 99, not working when instead of 10, replaced with 1000000000000 and 99 replaced with 9999999999999999.

Okay after replacing int with long, indeed I could accept input from 13 to 16 digit numbers.

#include <stdio.h>
#include <cs50.h>
int main(void)
{
long input;
do
    {
      input = get_long("enter");
    }
while (input<1000000000000 || input>9999999999999999); 

}

1 Answer 1

1

Hold that thought! If you restrict the input as with a do-while loop, program will continue prompting for the number until it is in the desired range. How will program be able to print correct output as per example:

$ ./credit
Number: 6176292929
INVALID

The problem in the code with the "big numbers" is because input is declared as int, not long. It will not compile on CS50 IDE using make.

You must log in to answer this question.

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