(CS50) CREDIT - PROBLEM SET 1 | SOLUTION

preview_player
Показать описание


––– DISCLAIMER –––

The following videos are for educational purposes only. Cheating or any other activities are highly discouraged!! Using another person’s code breaks the academic honesty guidelines. This solution is for those who have finished the problem sets and want to watch for educational purposes, learning experience, and exploring alternative ways to approach problems and is NOT meant for those actively doing the problem sets. All problem sets presented in this video are owned by Harvard University.

–––
Рекомендации по теме
Комментарии
Автор

As a beginner I did well solving all other problems by myself without google. Tried this one for 10 hours without success and surrendered into your video. Came into conclusion that info on the lecture and short clips was not enough, this problem is way to complicated for my level.

WiccanEquilibrium
Автор

This is like teaching someone 10 words and then telling them to write a 3 page paper

ATothFTW
Автор

I dont know if i'm the only one but i found that problem was so hard for an "introduction to computer science" it really took me time and i didnt found it thank you !

Sarawlawlawlaw
Автор

Jesus this so tough it took me a week just to comprehend the first half of the problem. Your are so smart omg

besegawgable
Автор

For the Amex, Visa, and Mastercard check functions, instead of hard-coding the number you want to raise 10 to the power of, you can instead raise 10 to the power of i. You can set "i = cardlength - 2" for Amex and Mastercard to check for the first two numbers, and "i = cardlength - 1" for Visa since we only check for the first number.

So, for Visa, you would only need one if statement that checks if both cardlength is 13 OR cardlength is 16. And then, because you're raising 10 to the power of i, it can adjust dynamically to the number of digits in the card number. This eliminates the need for two separate if statements. Also, if Visa were to ever add additional card numbers with lengths that were different from 13 or 16, let's say 15, you could just add into the original if statement "|| card length == 15" and the function would work properly without further modification.

Here is my function that checks if it's a Visa card:

bool visacheck(long cardnum, int cardlength)
{
if (cardlength == 13 || cardlength ==16)
{
int i = cardlength - 1;
int firstnum = cardnum / pow(10, i);

if (firstnum == 4)
{
return true;
}
else
{
return false;
}
}
return false;
}

David-vilg
Автор

seems significantly heavier than other tasks in practise 1

Lordicusss
Автор

They really just went in and made this a Week 1 Problem Set, lol. A literal 100 lines of code for a "Beginner" level problem set, amazing.

SCRKT
Автор

You are excellent my first time coding from scratch I did understand some of the things but I was getting lost on the debbuging but the code I understood way better

vxhtvfs
Автор

I was SOOOO proud when I could identify between the digits and the starting numbers. But oh boy, when I got to the Checksum, Truly mind blown by its difficulty!

hanieg
Автор

awesome!!

I was having a hard with this one, so i watched your video and just sleep on it.
The next day, with just a few checks, I could code this thing and even find my own route through the problem, Thanks very much! 🙏

PedroSantos-ltiy
Автор

Awesome video and so much value!! Even as a beginner i could understand and learned a lot! thanks for the great work

psampaioc
Автор

I’ve watched a few tutorials and I must say this is the most logical/sensible! Kudos!

tigerbytes
Автор

Spent so much time trying to solve this and it turns out that I didn't read the directions correctly about adding the digits of the products. ex( 1+2 and not 12)

rottoncookies
Автор

this tutorial use much more abstraction in a logical way than my version. will try to create a version similiar like this in the future. thank you

handsomebon
Автор

This is too hard for a beginner in my opinion, I've spent 9 hour but stucked. Your video really helped me, especially your logic flow for the credit card and then i go back to my code then i solved it :))

mathmaster
Автор

Showing up here to see the problem from another perspective, good to see how the same problem can be solved with different logics but definitely that's a better way to do it, good to learn.

ErickChavesBarreto
Автор

Its way harder than the others, its really desmotivating and in a way it makes no sense to give students such a hard excercise. I did others with cero help but with this I had to use yt for help. Nice explanation but I really think that there is no comparison between this level of difficult and the others in the first week

ezequielfraga
Автор

Question Please:

Why do you switch between file naming conventions using snake_case ( credit_card )and camelCase ( isAlternateDigit ) for the different variable names in your 'credit.c' code file, please?

Thanks in advance,

Peter

PeterDee-mq
Автор

Thanks a bunch! this is a great approach, keep it up guys!

nourhamdi
Автор

Thank you, i struggle a lot how to get the digit that i just ended up with wildly confusing code. Your video helped me cut down my ineffecient junk part.

pieterchristyan