Skip to content

Checkpoint: Your First Study Plan

The Course
•
25 min study

This checkpoint combines everything from today, with less guidance. A program that compiles isn't necessarily correct: the compiler checks that your code makes sense, not that it matches the brief. So write the expected report by hand before you run anything, then compare.

A good report derives its answers. If a total is calculated from the inputs, changing an input updates the output. If the total is typed in by hand, the program only looks correct until the first change.

Warm up: hard-coded or derived?

Both programs below print the same line today. Change read to 40 in each one and predict what happens.

Hard-coded C#
int read = 30;
int review = 15;
Console.WriteLine($"{read} and {review} make 45 minutes");
Check your prediction
Text
30 and 15 make 45 minutes
Derived C#
int read = 30;
int review = 15;
Console.WriteLine($"{read} and {review} make {read + review} minutes");
Check your prediction
Text
30 and 15 make 45 minutes

After your change, only the derived version still tells the truth.

Build it yourself

Attempt this without looking back if you can. Check every line of your output against the example, including capitals and spaces.

Exercise

A one-day study plan

Store a topic (Variables), the minutes for reading (35), the minutes for practice (50) and the number of minutes already finished (25). Print this report, calculating the total, the remaining minutes and the hours-and-minutes split from your variables:

  • Topic: Variables
  • Planned: 85 minutes (1h 25m)
  • Finished: 25 minutes
  • Remaining: 60 minutes

Then change the practice minutes to 65 and confirm that three numbers change while the topic and finished minutes don't.

Your workspace C#
string topic = "Variables";
Console.WriteLine($"Topic: {topic}");
Hint 1: the idea

Store only the four facts you were given. Everything else in the report can be worked out from those.

Hint 2: a first step

Add one variable for the planned total first, and print the Planned line without the hours. Add the split with / and % once that works.

Show one solution
C#
string topic = "Variables";
int reading = 35;
int practice = 50;
int finished = 25;

int planned = reading + practice;
int remaining = planned - finished;

Console.WriteLine($"Topic: {topic}");
Console.WriteLine($"Planned: {planned} minutes ({planned / 60}h {planned % 60}m)");
Console.WriteLine($"Finished: {finished} minutes");
Console.WriteLine($"Remaining: {remaining} minutes");
Text
Topic: Variables
Planned: 85 minutes (1h 25m)
Finished: 25 minutes
Remaining: 60 minutes

planned and remaining are calculated from the other variables instead of typed in, so changing reading or finished updates every line that depends on them. planned / 60 is whole-number division, which drops the remainder, and planned % 60 is exactly that remainder, so together they give hours and minutes.

Set finished to 100. The program prints a negative remaining time, and that's accurate arithmetic but a poor report. Tomorrow's lesson gives you the tool to decide what to do about it.

Was this article helpful?

Your response is saved on this device.