Tag Info

You could take the number as a string, and access the individual digits as characters (subtract '0' or 48 to obtain their value), or parse the number as a long long int and use for example / and % in ...
• 20.9k

credit - Why this AMEX and MASTERCARD numbers are considered invalid?

Found it: American Express starts with 34 or 37, Master Card starts with 51, 52, 53, 54 or 55. This makes those two numbers INVALID despite good checksum :)
• 163
Accepted

I keep getting "expected EOF" when I use check50

When the code is run with the test data that check50 uses, 4111111111111113, it prints INVALID twice. check50 was expecting the program to end, not to print the second INVALID. The problem is obvious ...
• 68.8k

Pset 1 Credit Card ( help needed )

Good job reaching that point and giving a shot to the hacker pset too! Don't be dismayed if you don't succeed with the first try, keep trying! Now to your question. First of all when you declare a ...
• 7,396
Accepted

Credit - Why Does it Fail Passing check50?

I feel your frustration, but you're looking in the wrong place. The number may pass the checksum calculation, but that isn't the problem. The number is only 10 digits. It should be either 13 or 16 ...
• 68.8k
Accepted

Credit.c is my nemesis

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 ...
• 20.9k

long long to array, how did you do?

You can use a loop. As long as the number is not zero, process its last digit (%10), for example storing it in an array, then divide the number by 10, shifting decimal digits to the right. If you ...
• 20.9k

You need to play around with the modulus operator for a bit. I don't want to give away too much, but when I did it, I used the truncation of the operator to my advantage ;)
• 182

credit.c frustration

1- converting longlong to int causes imprecision since int store 4bytes(32bits) and longlong store 8bytes(64bits) of intger values so you don't need int or float(for floating point numbers) which both ...
Accepted

I have problems applying Credit in python

If you were to print(warehouse) after this line warehouse = ((c_number / 10)%10)*2 you'd discover that it returns a floating point number. Python doesn't do integer division like C unless you use ...
• 18.7k
Accepted

pset1 | error: invalid operands to binary expression ('long long *' and 'int')

FindLength is a pointer, not a long long integer. This means that the code is trying to divide an address by an integer. FindLength = FindLength / 10; In this statement, FindLength contains the ...
• 68.8k
Accepted

PSET1 - Credit HELP

Your algorithm is calculating the correct result. 74 is the octal representation of decimal number 60 (octal uses 8 as base while decimal uses 10). Use ld, not lo to print a long. 7 * 8^1 + 4 * 8^0 = ...
• 20.9k
Accepted

problem with pset6 python credit

One thing first, and has higher precedence than or. A or B and C is same as A or (B and C). Keep that in mind when combining the two. In Python, pretty much like in C, firstTwo == 51 or 52 or 53 or ...
• 20.9k

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 ...
• 68.8k
Accepted

Can't use get_long_long();

Does cs50.h have a function called get_long_long?. There is no function by that name listed in the CS50 Reference. And notice this from the spec: Now, get_long itself will reject hyphens (and more) ...
• 28.4k
Accepted

Pset6 credit python Problem

The function get_int returns an integer and therefore if you wish to access each character by its corresponding index consider first casting it to a string.
Accepted

Why is this while loop generating errors

Assuming the error you are getting is not related to a linking error, which is common, then the error I assume you are getting is loop_check.c:14:15: warning: '&&' within '||' [-Wlogical-...
Accepted

PSET1 - Credit: Check50 says wrong what should be right

4111111111111113 isn't a valid card number because it doesn't come out correctly with the Luhn algorithm. It looks like you've got the part of the problem where you check the card's company, but it ...
• 744

CS50x PSET1 Credit <class 'pexpect.exceptions.EOF'>

From the spec: your programâ€™s last line of output [should] be AMEX\n or MASTERCARD\n or VISA\n or INVALID\n, nothing more, nothing less. This program will print "something more" if the ...
• 28.4k
1 vote

Why does this code sometimes give me a different sum when i run it for the same cc number?

After while (cc_number > 0) { cc_number /= 10; count ++; cc_number--; } cc_number is -1, so second while loop is never entered. Which leaves the indv_digit uninitialised completely. ...
• 20.9k
1 vote
Accepted

get_long_long getting different number

12 in octal (base 8) is 14, is it significant, no ?, 123 in octal is 173. Well it seems clear what we are doing, maybe you want is: printf("%lld\n", card);
• 5,169
1 vote
Accepted

pset1 credit arrays

The strcat function will need two pointers, the name of the array is one the other we can obtain with the address operator & as indicated by your error: strcat(temp1, &cc_number[i]);
• 5,169
1 vote

Problem - CS50x Credit Pset1

You could create a new variable outside of the while loop called result, and initialize it to 0. Then, inside the while loop, after you get the second to last digit, you can double it, and then loop ...
• 196
1 vote
Accepted

PSET1 / Credit / Modulo problem / Error: invalid operands to binary expression ('double' and 'double')

the definition of the pow function says that it returns a double that is the reason of your error, since the operator modulo requires integers, it is possible that it works if we do a casting although ...
• 5,169
1 vote

Credit.c is my nemesis

I got you, man. A little more experience with programming and you'll get there. Try including math.h and using some of its methods for counting and sorting through the digits. Here's my code as an ...
1 vote

I'd suggest a different method of turning your long long into an array: (1) Declare a char array with char s[20]; (20 digits should be enough for a long long), (2) Use sprintf to pass num into char ...
1 vote
Accepted

How can I pass an array or a long long unsigned variable as an argument to a function?

You ask: "However, my question remains: what would it take to properly pass a long long as an argument to a function?" Pass the argument to the funcion. Pass it with the correct type. Your function ...
• 1,687
1 vote

pset1 Credit: how to write it shorter

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 ...
• 20.9k
1 vote

CS50 Pset1 credit card

It means your main function should always return 0; after doing its work. The return value of the main function at the same time is the exit code of your programme, with a value of 0 usually ...
• 20.9k
1 vote
Accepted

Problem with pset1 credit

The doubling of digits starts with the second to last, not with the second. There's a difference for even number of digits. It's probably a coincidence if some of the numbers pass (or they are ...
• 20.9k

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