'F' → Fullscreen
Everything today goes in a new program named 1-11-weather.
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.
int temperature = 31;
Console.WriteLine($"Temperature: {temperature}");Console.WriteLine($"Above freezing: {temperature > 0}");Console.WriteLine($"Below boiling: {temperature < 100}");bool — the fourth type from Activity 1.5. You typed those by hand. These are produced by the comparison on the right of the =.isExactlyFreezing uses two equals signs. One would mean something completely different, and Task 4 shows you exactly what.int temperature = 31;int humidity = 82;
Console.WriteLine($"Temperature: {temperature}");Console.WriteLine($"Above freezing: {temperature > 0}");Console.WriteLine($"Below boiling: {temperature < 100}");Console.WriteLine();
bool isHot = temperature >= 30;bool isHumid = humidity >= 70;bool isExactlyFreezing = temperature == 0;
Console.WriteLine($"Hot: {isHot}");Console.WriteLine($"Humid: {isHumid}");Console.WriteLine($"Exactly freezing: {isExactlyFreezing}");bool.Parse rather than int.Parse. The user has to type true or false, which is why the prompt says so.int temperature = 31;int humidity = 82;
Console.WriteLine($"Temperature: {temperature}");Console.WriteLine($"Above freezing: {temperature > 0}");Console.WriteLine($"Below boiling: {temperature < 100}");Console.WriteLine();
bool isHot = temperature >= 30;bool isHumid = humidity >= 70;bool isExactlyFreezing = temperature == 0;
Console.WriteLine($"Hot: {isHot}");Console.WriteLine($"Humid: {isHumid}");Console.WriteLine($"Exactly freezing: {isExactlyFreezing}");Console.WriteLine();
// Ask the user for a wind speed and convert it to a whole number// Store whether the wind is at or above 40// Store whether the wind is NOT exactly zero// Display both results with labels
// Ask whether the boat is in open water// That answer is already true or false, so use bool.Parse// Display that answer with a labelThree runs of your finished program. Write down exactly what happens each time, copied from the screen, and change each one back before the next.
yes when it asks about open water.isExactlyFreezing to use a single equals sign. Try to run it.string instead: change int to string and remove the int.Parse(...) wrapper, keeping Console.ReadLine(). Try to run it.For each one, record the error code — something like CS0029 — or the exception name, and the line number it names.
Two of these never ran at all. One ran, then stopped. Say which is which, and how you can tell from the screen.
Console.WriteLine(string.Compare("9", "100") > 0);"9" and "100" as text gives that result when comparing 9 and 100 as numbers would not.int score = 85;bool passed = score >= 60;bool perfect = score == 100;bool failed = score != 100;score ← 85passed ← score ≥ 60perfect ← score = 100failed ← score ≠ 100This is the panel where the two notations disagree most. Read the middle row carefully.
| Meaning | C# | Exam notation |
|---|---|---|
| Put a value into a variable | = | ← |
| Is equal to | == | = |
| Is not equal to | != | ≠ |
| Greater or equal | >= | ≥ |
| Less or equal | <= | ≤ |
A single = means assignment in C# and equality on the exam. The same character, two opposite jobs, depending on which notation you are reading.
Because the exam uses ← for assignment, there is no ambiguity within the notation — the confusion only happens when you switch between the two. When you see score = 100 on an exam question, it is asking a question, not setting a value.
There is no bool.Parse on the exam. The reference sheet has exactly one way to get input, INPUT(), and it is not typed — it just returns whatever the user gave.
So a yes-or-no question on an exam looks like answer ← INPUT() followed by a comparison, with nothing converted. Converting input is something C# requires and the exam notation does not have.
Your finished program should run like this.
Temperature: 31Above freezing: TrueBelow boiling: True
Hot: TrueHumid: TrueExactly freezing: False
Wind speed? 12 [Enter]High wind: FalseWind is moving: True
In open water? (true/false) true [Enter]Open water: TrueTrue or False, with a capital letter.False for high wind and True for moving.Answer the following questions before submitting your work.
passed stores the answer to a question rather than a number. Why is that more useful than storing the score again?= and == in C#, as if to someone who has never programmed. Then describe a mistake you could make by forgetting that a single = means “is equal to” on the exam.Submit five things to the dropbox:
true.