7.x — Chapter 7 summary and quiz

📘 Chapter 7⏱ about 2 min read✍️ Beginner friendly
Read one box at a time. No rush.

Quick review#

  • Compile errors stop the build. Logic errors make wrong results.
  • Fix the first error message first. Check the line above, too.
  • Turn on warnings and fix them all.
  • Print values or use a debugger with breakpoints to see what's happening.
  • When stuck: make it smaller, explain it, take a break, then ask.
Quick check

Pick an answer. You find out right away if it is right.

Quick check #1

Your program compiles and runs, but prints the wrong answer. What kind of error is that?

Quick check #2

The compiler shows 25 errors. Which should you fix first?

Quick check #3

What is a breakpoint?

Quiz time
Question #1

Is each one a compile error or a logic error?

  1. Forgetting a ;
  2. Using <= instead of < so a loop runs one too many times
  3. Misspelling a variable name
  4. Using = instead of == in an if
  1. Compile error
  2. Logic error
  3. Compile error
  4. Logic error (it compiles, but sets the value instead of comparing). Warnings often catch it.
Question #2

This should print the average of three numbers, but it prints the wrong answer. Find two problems.

C++
int a { 4 };int b { 5 };int c { 7 };std::cout << a + b + c / 3;
  1. Missing brackets: c / 3 happens first. It should be (a + b + c) / 3.
  2. Integer division throws away the decimal part. Use 3.0: (a + b + c) / 3.0 gives 5.333....
Question #3

What does it mean to "step into" a line in a debugger?

If the line calls a function, the debugger goes inside that function and pauses on its first line, so you can follow it step by step.

Finished reading? Tick it off. Your progress is saved in this browser.

Tip: press ← / → to move between lessons, / to search.