'F' → Fullscreen
Everything today goes in a new program named 1-12-launch.
How to read the code blocks. Each task's code block shows your whole program, from line 1, as it should look when that task is finished.
You never start a new file and you never delete your work. The green lines marked with a + are the ones you add or change for that task — everything else is already in your file. Do not type the + sign.
Where a block shows only comments, you write that code yourself. The comments stay in your file.
fuelPercent to 80 and run it again. The warning should vanish — but Check complete has to print both times. If it does not, your last line is inside the braces.if, and the line it controls is indented four spaces. C# does not require this. Your reader does.int fuelPercent = 12;
Console.WriteLine($"Fuel: {fuelPercent}");
if (fuelPercent < 20){ Console.WriteLine("WARNING: fuel low.");}
Console.WriteLine("Check complete.");else to the fuel check, then a second decision for the crew count.int fuelPercent = 12;int crewCount = 7;
Console.WriteLine($"Fuel: {fuelPercent}");
if (fuelPercent < 20){ Console.WriteLine("WARNING: fuel low.");}else{ Console.WriteLine("Fuel level nominal.");}
Console.WriteLine($"Crew: {crewCount}");
if (crewCount >= 5){ Console.WriteLine("Full crew aboard.");}else{ Console.WriteLine("Running short-handed.");}
Console.WriteLine("Check complete.");int fuelPercent = 12;int crewCount = 7;
Console.WriteLine($"Fuel: {fuelPercent}");
if (fuelPercent < 20){ Console.WriteLine("WARNING: fuel low.");}else{ Console.WriteLine("Fuel level nominal.");}
Console.WriteLine($"Crew: {crewCount}");
if (crewCount >= 5){ Console.WriteLine("Full crew aboard.");}else{ Console.WriteLine("Running short-handed.");}
Console.WriteLine("Check complete.");Console.WriteLine();
// Ask the user for a cargo mass and convert it to a whole number// If the mass is over 500, refuse the launch// Otherwise approve it, and show the mass in the messageThree more runs of your finished program. Write down exactly what happens each time, copied from the screen, and change each one back before you try the next.
if (cargoMass). Try to run it.bool isHeavy = false;, and change the check to if (isHeavy = true). Run it and enter a mass of 100.if (isHeavy == true) — and run it again with a mass of 100. Then run it once more with a mass of 9000 and write down what it says.For each one, record the error code — something like CS0029 — or the warning code, and the line number it names.
One of these never ran. The other two both ran, and neither of them ever looked at the cargo mass. Number 2 refuses every load. Number 3 approves every load — which is why 100 kg looked fine and 9000 kg did not.
Say how a person reading only the 100 kg output could have caught number 2, and why the same person would have had no way at all to catch number 3.
> to >= and run it with exactly 500 again.if (score >= 60){ Console.WriteLine("Pass");}else{ Console.WriteLine("Fail");}IF(score ≥ 60){ DISPLAY("Pass")}ELSE{ DISPLAY("Fail")}Look at the shape before you read the words. The braces sit in the same places in both, and else is on a line of its own in both. That is not a coincidence — this course writes C# the way the reference sheet writes pseudocode, so you are learning one layout instead of two.
Only two things actually differ:
IF and ELSE are capitalized.IF(condition), not IF (condition).The condition itself uses the operators from Activity 1.11: ≥ rather than >=, and a single = where C# needs ==.
What is missing from the reference sheet matters too. There is no ELSE IF anywhere in the exam notation.
C# has one, and you will meet it next activity. Activity 1.13 is about what the exam notation does instead — and about why the shape it forces you into is worth seeing before you reach for the shortcut.
Today is the first time your code has had a block in it, so it is worth knowing that every language has to answer one question: where does this block stop? Nothing about the answer is obvious, and the people who designed these languages did not agree.
if (score >= 60){ Console.WriteLine("Pass");}else{ Console.WriteLine("Fail");}if (score >= 60) { Console.WriteLine("Pass");} else { Console.WriteLine("Fail");}if score >= 60: print("Pass")else: print("Fail")if score >= 60 then print("Pass")else print("Fail")endAll four programs do exactly the same thing. The first two are the same language, and only the position of one character changed. Python throws the braces away and uses the indentation you were going to write anyway. Lua, and Ruby, and old versions of BASIC, spell the end of a block as a word.
This course writes the first one, with the brace on its own line. Two separate reasons point the same way here, which is not usually how style arguments go: it is what the exam reference sheet does, and it is also the ordinary convention for C# itself — Visual Studio formats your code that way by default, and Microsoft's own documentation is written in it.
You will still meet the second one constantly, just not in C#. It is the dominant style in JavaScript, Java, C, and C++, so a great deal of the code you find online looks like that. Read it without flinching. To the compiler the two are identical; a machine reading your code does not care where the newlines are.
Worth knowing why anyone argues about it. Braces on their own lines put every opening and closing brace in the same column, so a missing one is easy to spot — which is exactly the error you are most likely to make this week. Braces on the same line fit more code on a screen. Python's answer ends the argument and starts a different one, because now an invisible character — a space — changes what your program does.
Your finished program should run like this.
Fuel: 12WARNING: fuel low.Crew: 7Full crew aboard.Check complete.
Cargo mass? 620 [Enter]LAUNCH REFUSED: cargo too heavy.Answer the following questions before submitting your work.
if and else, exactly one of the two blocks runs. What would it mean for a program if both could run?Submit four things to the dropbox: