Learning how to code in my middle age - Week 1 [C - part 1]
coding in frustration

Learning how to code in my middle age - Week 1 [C - part 1]

By NewToCrypto | New to crypto | 16 Jun 2020


So after a smooth sailing into coding via Scratch a couple of days ago, I decided to continue with C.

I watched the lecture, read the notes, and proceeded to do the assignment. The first one was an easy "Hello world." Then the second one hit me with tons of bricks. I thought I understood everything covered in the lecture? How do I actually use that information to do my assignment though? 

I am supposed to make a right-aligned triangle made of "#". I prompt a user to input any number from 1 to 8 inclusive. If the person enters something outside of the parameter, say -1 or 100, then I'm supposed to re-prompt the user until the correct number is entered. I have so many questions my whole body hurts. 

Q1: while(n < 0) OK, why is n supposed to be less than 0 and not 9? This reads to me like this condition is never going to be met. But my code runs... How/why?

Q2: So I assigned i for rows and j for columns. How does C know which is which? (Because I nested j under i and C automatically picks the first one as the row?)

Q3: Ugh, instead of printing a triangle, it's giving me a square of #s! (Change the condition. j < i seems to work.)

Q4: When I enter, say, 7 when I'm prompted, I get 6 rows of #s. Why is it missing a row? (Because I used a condition n < 9 earlier, and then assigned i < n. It should have been i <= n.)

Q5: I hate keeping track of those curly brackets! (Consider studying Python in the future?)

Phew, it took me three hours just to make a left-aligned pyramid! 

Now onto making a right-aligned one. Fun times!

I'd like to conclude this post with a piece of good news. Last weekend, I applied for assistance to get a 90% discount on the verified certificate for CS50x. Today I received a message from EdX with a discount code! Yeah! I'm broke AF but can totally afford US$9! This gives me even more motivation to finish this course. 

 

 

Related Posts:

This pandemic really screwed up my life and I’m kind of lost

Starting over again - Learning how to code in my middle age (fun, fun fun!)

Learning how to code in my middle age - Week 0 [Scratch]



New to crypto
New to crypto

A newbie taking wobbly first steps in the brave new cryptocurrency world. Nothing useful for seasoned crypto warriors to see here.

Send a $0.01 microtip in crypto to the author, and earn yourself as you read!

20% to author / 80% to me.
We pay the tips from our rewards pool.