Learning to Code: Week 2 – mario.c

5/20/16

  • Loops: while, do-while, for
  • Boolean values: and is &&, or is ||, not is !
  • Compilers: Pre-processor, compilation, assembly, linking
  • Functions: Saves time in programming
  • Libraries: CS50 has their own library.
  • Make & Clang: “Make” is made by CS50
  • Precedence: Which operations go first? ++i vs i++
  • Style: Comments and in-line vs multi-line comments
    • Indentation of 4 spaces
    • Don’t need { if only 1 line
    • Variable names (don’t make them hard to understand for someone else), don’t make them too long and use underscores to separate words in variables.
    • * next to pointer’s type and not the variable. No idea what a pointer is yet.

5/21/16

Week2Lecture2
Week 2 Lecture 2

5/22/16

Worked on program pset1 water.c

Thought Process:

  1. Prompt the user for the number of minutes showered.
  2. If not a positive integer then retry.
  3. Once we have a positive integer showertime then take that number and multiply by 192 and then divide by 16 to get the number of bottles.
  4. Round up or down when calculating the number of bottles?
  5. Print that number of bottles used to the screen.
  6. Done.

My solution below:

Next program task is itsamario.c

5/23/16

No laptop power, so I wrote out my thought process and code for itsamario on paper for an hour or so.

5/24/16

Unfortunately had no time to code. Tried to read a bit of the Code book. Frustrating. 😞

5/25/16

Worked on and completed itsamario.c

Problems/Thoughts:

  • In for loop I used a comma instead of a semi-colon which I couldn’t figure out for a bit.
  • If I declare a variable inside of a loop it can’t be used outside of that loop? Had to put the height outside of the do-while loop and then it worked.
  • I created my first loop for the spaces first and used 0 instead of a space so I could actually see what was being printed.
  • Changed 0 to a space after the program fully worked.
  • Getting the loops to work for the spaces and #’s was kind of a pain the ass, but basing it off of the row number i made it much easier and cleaner than when I did it before.
  • I will post what my old solution was from whenever.
  • My do-while loop conditions weren’t correct at first.
  • Fixed after the check program gave me the errors.

My solution below: