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.
int read = 30;
int review = 15;
Console.WriteLine($"{read} and {review} make 45 minutes");Check your prediction
30 and 15 make 45 minutesint read = 30;
int review = 15;
Console.WriteLine($"{read} and {review} make {read + review} minutes");Check your prediction
30 and 15 make 45 minutesAfter 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.
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: VariablesPlanned: 85 minutes (1h 25m)Finished: 25 minutesRemaining: 60 minutes
Then change the practice minutes to 65 and confirm that three numbers change while the topic and finished minutes don't.
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
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");Topic: Variables
Planned: 85 minutes (1h 25m)
Finished: 25 minutes
Remaining: 60 minutesplanned 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.
Completion is saved in this browser only. It does not measure mastery.