Skip to main content
2 votes
Accepted

Pset1- Credit: Length of the number by continuously dividing by 10

Review the week 1 video starting at around 1:22:00. From the transcript: If they are both ints, by definition of how C works, you are going to get back an integer as your answer. So if you do 1 ...
DinoCoderSaurus's user avatar
2 votes

error at while loop cs50 Pset1 credit

The compiler is actually giving a warning, but the compiler flags are set up to treat all warnings as errors. It's still best to eliminate all warnings. Here's the reason. For clarity, let's ...
Cliff B's user avatar
  • 69k
2 votes

Could not find the following in the output: <class 'pexpect.exceptions.EOF'>

I took a quick glance at the code. A couple suggestions that may resolve your issues. First, the standard is that a program returns 0 when it completes successfully, and returns non-zero when there's ...
Cliff B's user avatar
  • 69k
1 vote

Credit card problem: Unable to calculate the sum of entered credit card no

int mm = creditcardno; This should be a long, it is likely overflowing. You can add some printf for mm and mod1 to help you debug it.
Mirela Buruiana's user avatar
1 vote
Accepted

Unable to move to the next chunk of the problem

This while (cc > 0) is an infinite loop because neither the value of cc nor creditcardno changes, therefore cc is always > 0.
DinoCoderSaurus's user avatar
1 vote
Accepted

Credit : the checksum is correct for <10 digits, but for14,15,16 digits getting negative checksum

this is in need of major cleanup. organize your code and avoid repeating yourself. For example figure out how many digits are in the number once. save that value. Figure out the value of the i-th ...
UpAndAdam's user avatar
  • 1,456
1 vote
Accepted

pset1-credit I can't find the issue with my code

There are no dumb mistakes when one is learning; there's only "learning". At a quick glance, firsttwodigits = cc; is a big problem. At the 2nd iteration (when digits is 2), cc is still a &...
DinoCoderSaurus's user avatar
1 vote

I'm getting a floating point exception error in the credit code but I definitely haven't divided by 0

Found an answer! The reason was an overflow, since the condition (n % i) <= n would be true upto infinity and long long i would keep being multiplied by 100 until even long long cannot hold the ...
Certified Bibliophile's user avatar
1 vote
Accepted

there is a logical error I can't really catch up with

Two questions. What happens when an invalid number has the correct number of digits but doesn't pass the tests for any of the credit cards? Where does the code say it is invalid? When a card is ...
Cliff B's user avatar
  • 69k
1 vote
Accepted

Dealing with pset1's "credit" problem

It's a problem with the for statement setup. Look at the statement: for(int i = 0; i <= digit_number; i + 2) The increment clause i + 2 isn't properly written. This takes the value in i and adds ...
Cliff B's user avatar
  • 69k
1 vote
Accepted

Need Help, why does my debug50 show a correct result but when i run the program, thus it shows a wrong answer

Variables may (will?) be assigned different memory locations when run under debug50. This could cause different results when a variable is declared and not intialized. When it is used in, say, an ...
DinoCoderSaurus's user avatar
1 vote

credit.c I don't understand how to fix my code

It looks like you expect ^ to do exponentiation. It doesn't; it is the Bitwise XOR operator in C. You can use the pow function in the math library instead.
DinoCoderSaurus's user avatar
1 vote
Accepted

CS50 Credit Pset problem- Code keeps looping back to ask for the credit card number

The proximate reason for 378282246310005 not being identified as Amex is this number > (long) pow(10, 15) is false. Remember pow(10,15) is a 16 digit number. visual compare for the humans 1,000,...
DinoCoderSaurus's user avatar
1 vote
Accepted

Credit problem: Opening parentheses not matched with closing

Sometimes, the compiler can't quite figure out the real problem. But, at least it usually indicates roughly where it is! Look at the line of code: if (sum % 10 ! = 0) The problem lies with the ...
Cliff B's user avatar
  • 69k
1 vote
Accepted

Function in C: How to create

The structure is simple. Pay attention to placement of curly braces and semicolons, specifically, where they are NOT. #include statements // The next line is a function signature to tell the ...
Cliff B's user avatar
  • 69k
1 vote
Accepted

Do-while code for long integer input

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 ...
DinoCoderSaurus's user avatar
1 vote
Accepted

Segmentation Fault for PSet1 Credit in CS50

The code is not counting the number of digits correctly. It's generating counts that are one less than the actual length. You can verify this by inserting printf("cc_length = %i\n",cc_length)...
Cliff B's user avatar
  • 69k
1 vote
Accepted

expected expression error in pset1 credit for loop

Simple. A "for" statement cannot be used as the object of an assignment statement. x = for(...) just isn't allowed. A for statement does not return a value. It isn't a function call. I'm ...
Cliff B's user avatar
  • 69k
1 vote
Accepted

Stuck with pset1 credit question. I don't know why I'm not able to get any "Valid" outputs when a valid card number is entered

Short answer: your code is structured wrong, and you're never actually going through the Luhn Algorithm. General tip: work on indenting your code correctly. You can use the style50 tool (described ...
Llenk's user avatar
  • 744
1 vote

PSET 1 Credit AMEX

Your calculation must start at the second-to-last digit. The arithmetic you have displayed, starts at the last digit. From the first example: 378282246310005, the second-to-last digit is 0, step 1 ...
DinoCoderSaurus's user avatar
1 vote
Accepted

cs50 pset1 credit expected expression error

Look at the line in question: if(askPositiveLong >= 340000000000000 && askPositiveLong < 350000000000000) || (askPositiveLong >= 370000000000000 && askPositiveLong < ...
Cliff B's user avatar
  • 69k
1 vote
Accepted

How To Use a For Loop To Store Values Into Multiple Variables?

Since you have identified in your code sample above that you understand how to declare and put values in an array. Then I suggest the simple means is to just create an array of 8 length that can store ...
Nicknapoli82's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible