#include <stdio.h>
#include <cs50.h>
int main(void){
long long card;
int i;
int otherdigs;
int multiply;
int sum = 0;
int sumofothers = 0;
int finaladd;
int length;
int card_length;
long long get_card;
get_card = get_long_long(" Enter credit card: ");
card = get_card;
for (i = 0; i < 16; i++)
{
sumofothers += card % 10;
card /= 10;
otherdigs = card % 10;
card /= 10;
if (otherdigs*2 < 10)
{
multiply = otherdigs * 2;
sum += multiply;
}
else
{
otherdigs = otherdigs*2-9;
sum += otherdigs;
}
}
finaladd = sum + sumofothers;
if (finaladd % 10 == 0)
{
for (length = 0; length < 14; length++)
{
get_card /= 10;
}
if ( get_card >= 51 && get_card < 56 ) {
printf("MasterCart\n");
}
else if ( get_card >= 3 && get_card < 4)
{
printf("AmericanExpress\n");
}
else if ( get_card < 0 || (get_card/10 >= 4 && get_card/10 < 5) )
{
printf("VIZA\n");
}
else {
printf(" Sorry, We Don't Support This Payment Company\n");
}
}
else
{
printf("This credit card is not valid \n");
}
return 0;
}
I recently took cs50 online course and this is my solution to pset1 ( Credit ) This is my very first program that I actually thought through and did it all myself. The goal is to get the card number from user and check if it's valid ( Luhn’s Algorithm )
I know the style is awful and the code is very messy too, but your opinion is very important to me... I spent maybe 5,6 hours for this. The question is do you think I can code? Become a programmer ? I mean do I have the right mind for it ? ( since this is my first without guide code ) BTW, I have no prior programming experience (only read some pages of K&R 2 years ago),
I even don't know half of c syntax yet. I know talent is a myth and all, but based on this code, do you think I'm any good at this?