• This topic is empty.
Viewing 1 post (of 1 total)
  • Author
    Posts
  • #98
    admin
    Keymaster

      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.


      Reply


      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); 
      }

      https://cs50.stackexchange.com/questions/41891/do-while-code-for-long-integer-input[learn_press_profile]

    Viewing 1 post (of 1 total)
    • You must be logged in to reply to this topic.
    Scroll to Top