- This topic is empty.
Viewing 1 post (of 1 total)
Viewing 1 post (of 1 total)
- You must be logged in to reply to this topic.
IT, Programming, & Web Development › Forums › CS50’s Introduction to Computer Science by Harvard University on Edx › Week 1: [C] – Data Types, Operators, Conditional Statements, Loops, and Command Line › Pset1 credit card problem: Problem with if statement while classifying into Amex/Visa/Mastercard
While classifying, I could see MasterCard being correctly spotted but not Visa (not checked yet Amex).
[dm_code_snippet background=”yes” background-mobile=”no” slim=”yes” line-numbers=”yes” bg-color=”#abb8c3″ theme=”dark” language=”clike” wrapped=”yes” height=”” copy-text=”Copy Code” copy-confirmed=”Copied”]
//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"); }
[/dm_code_snippet]
Reply
https://edstem.org/us/courses/176/discussion/708180?comment=1644439[learn_press_profile]