'F' → Fullscreen
Everything today goes in a new program named 1-13-storm.
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.
windSpeed: try 80, then 46, then 5. Write down what each one prints.int windSpeed = 46;
Console.WriteLine($"Wind speed: {windSpeed}");
if (windSpeed >= 74){ Console.WriteLine("Category: hurricane");}else if (windSpeed >= 39){ Console.WriteLine("Category: tropical storm");}else{ Console.WriteLine("Category: calm");}This task rewrites the chain, it does not add to it. Your program goes from 16 lines to 32, and the hurricane branch becomes 1 - dangerous. The two bottom branches — tropical storm and calm — are the only ones that survive unchanged.
int windSpeed = 46;
Console.WriteLine($"Wind speed: {windSpeed}");
if (windSpeed >= 157){ Console.WriteLine("Category: 5 - catastrophic");}else if (windSpeed >= 130){ Console.WriteLine("Category: 4 - extreme");}else if (windSpeed >= 111){ Console.WriteLine("Category: 3 - devastating");}else if (windSpeed >= 96){ Console.WriteLine("Category: 2 - extensive");}else if (windSpeed >= 74){ Console.WriteLine("Category: 1 - dangerous");}else if (windSpeed >= 39){ Console.WriteLine("Category: tropical storm");}else{ Console.WriteLine("Category: calm");}int windSpeed = 46;
Console.WriteLine($"Wind speed: {windSpeed}");
if (windSpeed >= 157){ Console.WriteLine("Category: 5 - catastrophic");}else if (windSpeed >= 130){ Console.WriteLine("Category: 4 - extreme");}else if (windSpeed >= 111){ Console.WriteLine("Category: 3 - devastating");}else if (windSpeed >= 96){ Console.WriteLine("Category: 2 - extensive");}else if (windSpeed >= 74){ Console.WriteLine("Category: 1 - dangerous");}else if (windSpeed >= 39){ Console.WriteLine("Category: tropical storm");}else{ Console.WriteLine("Category: calm");}
Console.WriteLine();
// Ask the user for a rainfall total in millimeters and convert it// 200 or more is "flood risk"// 50 or more is "heavy"// 10 or more is "moderate"// anything else is "light"// Display the rainfall, then its single categoryReorder your rainfall chain so that the flood risk branch can never run, no matter what the user types. You are allowed to move lines, not to delete them.
else removed — so it becomes three or four separate if statements.This is the biggest difference between the two notations in the whole course — and it is the one Activity 1.12 promised you.
The exam reference sheet has no ELSE IF. It offers IF and it offers IF/ELSE, and that is all. A chain has to be built by putting a whole new IF inside the ELSE block.
if (score >= 90){ Console.WriteLine("A");}else if (score >= 80){ Console.WriteLine("B");}else{ Console.WriteLine("C");}IF(score ≥ 90){ DISPLAY("A")}ELSE{ IF(score ≥ 80) { DISPLAY("B") } ELSE { DISPLAY("C") }}Read the right-hand side carefully. The second IF is not a sibling of the first — it lives inside the first one's ELSE, indented a level deeper. The closing braces stack up at the bottom.
IF/ELSE, it is very often just a chain, written the only way the notation allows.A useful trick when you are tracing one of these: find the deepest ELSE and read it as “none of the conditions above were true.”
The ordering rule survives the translation. A nested exam-notation chain has exactly the same dead-branch problem, in exactly the same way, and the reference sheet will not warn you either. If the loosest condition is at the top, the branches underneath it are unreachable whichever notation you wrote them in.
Your finished program should run like this.
Wind speed: 46Category: tropical storm
Rainfall in mm? 64 [Enter]Rainfall: 64Category: heavyAnswer the following questions before submitting your work.
if statements instead of a chain.else if, so chains are written as nested blocks. Does that change what the program does? Explain your answer.Submit four things to the dropbox: