Skip to main content
5 votes

pset1 credit, need advice

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 ...
Blauelf's user avatar
  • 21k
5 votes

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 :)
smajli's user avatar
  • 163
5 votes
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 ...
Cliff B's user avatar
  • 69.2k
3 votes

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 ...
ChrisG's user avatar
  • 7,396
3 votes
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 ...
Cliff B's user avatar
  • 69.2k
2 votes
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 ...
Blauelf's user avatar
  • 21k
2 votes

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 ...
Blauelf's user avatar
  • 21k
2 votes

pset1 credit, need advice

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 ;)
Jason_V's user avatar
  • 182
2 votes
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 ...
curiouskiwi's user avatar
  • 18.7k
2 votes
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 ...
Cliff B's user avatar
  • 69.2k
2 votes
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 = ...
Blauelf's user avatar
  • 21k
2 votes
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 ...
Blauelf's user avatar
  • 21k
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
  • 69.2k
2 votes
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) ...
DinoCoderSaurus's user avatar
2 votes
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.
Ashen Gunaratne's user avatar
2 votes
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-...
Nicknapoli82's user avatar
2 votes
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 ...
Llenk's user avatar
  • 744
2 votes

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

Incorrect mastercard number in pset1

I'm not sure where you went wrong, but don't forget doubling the digits always starts with the second-to-last. 5 * 2 = 10 => 1 + 0 = 1 1 * 1 = 1 0 * 2 = 0 5 * 1 = 5 1 * 2 = 2 0 * 1 = 0 5 * 2 = 10 =...
Blauelf's user avatar
  • 21k
1 vote
Accepted

pset6 credit.py returns INVALID for correct card number

When you are consuming the cardNo = cardNo//10 you should be dividing by 100 rather than 10 so that you consume the last 2 digits each time. Otherwise, you will end up double-counting some of the ...
curiouskiwi's user avatar
  • 18.7k
1 vote

problem at the output of credit (pset1)

Don't use floating point. There's no need. You could just do x = creditNumber % 100; to get the last two digits. BTW, your code is overly complex. Try to get some information, like checksum, number ...
Blauelf's user avatar
  • 21k
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. ...
Blauelf's user avatar
  • 21k
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);
MARS's user avatar
  • 5,179
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]);
MARS's user avatar
  • 5,179
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 ...
Larpee's user avatar
  • 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 ...
MARS's user avatar
  • 5,179
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 ...
Adam Wiley's user avatar
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 ...
Blauelf's user avatar
  • 21k
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 ...
Blauelf's user avatar
  • 21k
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 ...
Blauelf's user avatar
  • 21k

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