Week 15: Small programs II

C code typing course. 24 wpm, 94% accuracy.

The programs this week read a number, check it with a condition, and print results with a loop. You do not learn any new symbol. Instead, you use &, %, < and ; from earlier weeks together in one piece of code. The goal is to write each line carefully, one at a time, and to split the program’s logic into small parts that you can check.

What you will learn

There are no new symbols. In these programs you will use these structures together:

  • scanf("%d", &number): reads a whole number from the keyboard. The & tells scanf where to store the value.
  • if (number % 2 == 0): checks whether the number is even.
  • for (int i = 0; i < number; i++): repeats a task as many times as the number.

Write each structure as a single line first, then combine them. This way, if something goes wrong, you know exactly which line to look at.

Technique tips

  • When you type %, your left index finger does the reaching. Bring your right hand back to the home row afterward.
  • Do not mix up & and &&. A single & gives an address, while a double && joins two conditions.
  • Count the parentheses on each line. Every line should have as many opening parentheses as closing ones.
  • Look at the screen. After a long line, check that the semicolon is at the end.

Lessons

  1. Lesson 1, learn (10 to 15 minutes): Watch the scanf, if and for lines one at a time. Type each one three times and explain its job in your own words.
  2. Lesson 2, practice (10 to 15 minutes): Write a short program that reads a number and prints whether it is even. Check that every line has its parentheses and semicolons.
  3. Lesson 3, review (10 to 15 minutes): Take the two-minute test with program lines. Save your result and practice the symbols you missed.

This week’s goal

This week’s target is 24 WPM and 94% accuracy. Finishing the week’s lessons earns you 1 star. Reach 94% accuracy for 2 stars, and also reach 24 WPM for 3 stars. When several structures work together, one error can break the whole program, so type carefully.

This week’s lessons

Do the lessons in order. Each one ends with a test, and your best result is saved.

  1. Lesson 1: Learn

    Keywords

    12 minutes

    Start
  2. Lesson 2: Practice

    Practice

    12 minutes

    Start
  3. Lesson 3: Review and test

    Review and test

    13 minutes

    Start

All weeks