• Skip to main content
  • Skip to footer

SoftwareProg.com

Software programming learning aide

  • Blog
    • Discussion
  • News
  • CS50’s Introduction to Computer Science by Harvard University on Edx
    • Week 1
    • Week 2
    • Week 3
    • Week 4
    • Week 5

Pset1 credit card problem: Problem with if statement while classifying into Amex/Visa/Mastercard

CS50 threads to aide as a supplementary resource › Forums › CS50’s Introduction to Computer Science by Harvard University on Edx › Week 1 › Pset1 credit card problem: Problem with if statement while classifying into Amex/Visa/Mastercard

  • This topic is empty.
Log In Register Lost Password
Viewing 1 post (of 1 total)
  • Author
    Posts
  • October 17, 2021 at 7:00 am #46
    admin
    Keymaster

      While classifying, I could see MasterCard being correctly spotted but not Visa (not checked yet Amex).

       


      Copy Code
      Copied
      Use a different Browser

      
      
       //check for American Express
          if ((firsttwodigits == 34 || firsttwodigits == 37) && (i == 15))
          {
              printf("Amex");
      
          }
          //check for MasterCard
          if (i == 16 && (firsttwodigits / 10 == 5) && (firsttwodigits % 10 == 1 || firsttwodigits % 10 == 2 || firsttwodigits % 10 == 3 ||
                  firsttwodigits % 10 == 4 || firsttwodigits % 10 == 5))
          {
                  printf("MasterCard");
      
          }
          //check for Visa
          if ((i == 16) && (firsttwodigits % 10 == 4))
          {
              printf("Visa");
          }
      
      


      Reply


      https://edstem.org/us/courses/176/discussion/708180?comment=1644439[learn_press_profile]

    • Author
      Posts
    Log In Register Lost Password
    Viewing 1 post (of 1 total)
    • You must be logged in to reply to this topic.
    Log In

    Log in / Register

    Initiative by Digital Splendid OPC Pvt. Ltd.