2

Your counting loop destroys the number. Destroy a copy instead. And stack variables are not initialised by default, so you end up with some arbitrary data as the array isn't filled at all due to your first mistake. While the use of one array for all the digits might be reasonable, the use of extra arrays is definitely not required. You can process one ...


2

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 simplify the expression to the essential parts. while((a) && (b) || (c)) The compiler isn't sure about how these logical operators should be combined. ...


1

This is because you've overlooked an important piece of information provided with the explanation of Luhn's algorithm. It actually says in the algorithm to add the products' digits to the checksum and not the product itself(which you've done). Here's an excerpt from the pset1 page for your reference: According to Luhn’s algorithm, you can determine if a ...


1

Having problems with this? temp_b /= (10 ^ 14); That would be because the ^ operator is not an exponent operator as it is in mathematics. It's the exclusive or operator. You might try a call to pow(). As for float issues, I didn't see any floats in the code at all. If this answers your question, please click on the check mark to accept. Let's keep up on ...


1

When you say number /= 10, you are actually reducing the number variable itself. So after counting and getting the value for count, the value of number is equal to zero


1

Look at the line in question: if(askPositiveLong >= 340000000000000 && askPositiveLong < 350000000000000) || (askPositiveLong >= 370000000000000 && askPositiveLong < 380000000000000) How are the parentheses???? Anything missing? I wonder if this problem exists anywhere else??? ;-) If this answers your question, please ...


1

Agreed that the example used can be ambiguous. We have updated the AP Credit problem spec with a better example that makes it clear that you must start from the last digit (and the first number to be multiplied by 2 is the second-to-last digit starting from the end (the right).


1

For the sake of discussion, let’s first underline every other digit, starting with the number’s second-to-last digit: 378282246310005 Second to last digit is the digit before the last digit, in this case, the last 0. It is saying to start with the last 0, and work your way to the left, using every other digit. It's done this way so that the calculation ...


1

Edit to rephrase, I hope this one is ok with the admin. Operate on a copy of the number (so that you can use the number later for other things). Use a loop, can be a pretty simple while loop, and process only the last digit (% 10), or the last two digits within the loop. After that, divide the (copy of the) number by 10 if you processed one digit, or 100 if ...


1

One of the hidden lessons in the first few psets is to write to the specification exactly. That means that anything extra, missing or misplaced, including prompts, output, whitespace, line feeds, comments, etc., will cause a fail, particularly with the automated grader check50. With that in mind, let's look at an example of your output: $ ./credit ...


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