elisabethirgens / cs50

Track my progress, keep some of the code and gather notes from CS50's Introduction to Computer Science

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Improve credit.c

elisabethirgens opened this issue · comments

This problem is from week 1, before we have gotten to for example arrays or functions, so I wanted to solve it using only the concepts that have been introduced so far in the program: data types, conditional statements and loops.

Even with these limitations, I think there are more potential improvements:

  • Can the checksum code be simplified with fewer variables? More resursive somehow?
  • Could the two while loops be combined to handle alternating digits?
  • Would a switch at the end be more readable than this weird nesting of if else?

Might also be interesting to see which other refactoring comes naturally after more weeks of programming with C.