CS50 — Week 1 (C):
Moving swiftly away from the user friendly Scratch to the intimidating, strongly-typed C was certainly a step up from the previous week and was really challenging. However, I was undeterred and recognised that this was the true beginning of the process to learn how to program.
The lecture was a fantastic overview of C and taught a lot of fundamental skills and the syntax required to be able to write programs in C, such as how to operate the dedicated CS50 integrated development environment (IDE), C basics such as placeholders and prompting for user input, and types used within programming. As a beginner to programming, I was unaware of all the different types including bools, chars, strings, floats, ints and longs. Naïvely, I assumed it was simply just letters or numbers and it was irrelevant how long the word or number was.
The lecture covered how to write loops (do while loops, while loops and for loops) and the shortest hand notation for doing so (syntactic sugar). Even with something relatively simple like loops, it took me a few tries to recognise which loops to use. Now, I recognise that do while loops are always executed once irrespective of the condition, whilst while loops only execute when the given condition is true.
As challenging as the content in Week 1 was, it was exciting to learn how to write basic programs in C and use syntax which was so alien to me previously. The true challenge lies in the labs and problem sets. During the lecture we are given the tools to build a program and then in the labs and problem sets we are given an end product. The missing link is the set of instructions and that is down to the programmer. Picking which tools to use and working out how to use them is unquestionably a vital skill that I am an amateur at for the moment but also I am progressing and learning from experience.
The lab in Week 1 prompts a user for a start and end population and calculates, using a population growth formula, how many years it would take for the start population to grow to reach the end population. This lab was a perfect example of a situation where I had to decide on which loop to use (while or do while) and challenged me to utilise the knowledge gained from the lecture.
The problem sets for Week 1 were even more difficult than the lab. For Mario (less), the program prompts a user for input between 1 and 8 for the height of a number of hashes to be printed. The hashes would eventually be printed in a pyramid shape similar to the image below. For Mario (more), I was tasked with mirroring the output of Mario (less) with a space between the two pyramids. The Mario problem challenged my understanding of for loops and required nested for loops to solve the problem.
Week 1 also consisted of the problem sets called Cash and Credit. With Cash, the program prompts the user to input a float figure for change owed. The program would then output the lowest number of US coins to make up the float figure. Cash was a test of while loops and required a series of them to solve the problem.
Credit was the more difficult problem set of the two. Credit takes as input a credit card number and would check that it was the correct length and that the numbers satisfied the Luhn algorithm. Credit would then print the type of card the credit card number was linked to e.g. Visa, Mastercard or Amex.
Week 1 was undoubtedly more difficult than Week 0 and really challenged the knowledge I’d acquired through taking notes on the lecture. Despite the lab and problem sets taking me a few days to complete, it was very rewarding and satisfying to complete them and write functional code.
Thank you for reading!