I started with the credit card case but I am lost I wrote this till now I want some help to know what to do next of course not giving the whole thing because this is the purpose of the course... please, provide me with clear hints

     #include <cs50.h>
     #include <stdio.h>

int main(void)
   int c;
   printf("Credit Card number:");
      c = get_long_long();
while (c<0);

  • 1
    If you watch the walkthrough, Zamyla does a reasonable job of giving you the steps to follow. You need to iterate through the numbers of the credit card (from the end - backwards), run a few checks and then add & compare the sums. One suggestion is to use modulo - using something like c%10, will help you to iterate through the digits. It taxes the brain, but that helps to cement the learning & knowledge. Cheers. – MadDogDean Jul 2 '17 at 6:18
  • Do you mean you started with credit.c and not from week0's problem set and so forth? If you did, I suggest that you start from the very beginning, otherwise you will probably quickly become stuck and quit. It is better to spend ~20 hours to get to this problem than dive right in unless you already have programmed in c before. – dumbitdownjr Jul 2 '17 at 18:50
  • I finished week 0 already before but my problem is with the last case of the pset1 , I watched Zamayla's video but there are few things that are not clear – Hasan Alaa Nassr Jul 4 '17 at 10:52

There are quite a few ways to approach this problem and that's been pretty difficult for me to wrap my head around too. I'm still working on this problem but I decided to convert my long_long variable into a string using strlen and sprintf in order to start by ruling out all card length values that were not 13-16 digits long. That way, the user will immediately get an "Invalid" response at the get-go if they put in 10 or 12 or 20 digits. Originally, I tried limiting the input range as an int value from the long_long but it coded to the actual numbers 13, 15, 16 instead of the digit length. I would start there. It took me some time to figure out how to use strlen and sprintf in this context but I think it's coming along. Good luck.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .