Part 5 - If Statements

This section covers how to use decision structures in your programs and how to generate random numbers in C#.

Decision Structures

What to Do?

1 - Read through Decision Structures. Solutions are provided as well.

2 - Open up your Part 4 - Random Assignment and add error checking

      • OPTIONAL: This is a good opportunity to experiment with Git. Visit the Git Tutorials section, and read the tutorial on how to add an existing solution to source control.

      • Use Int32.TryParse() to verify that the user input is numeric, provide a descriptive error message otherwise.

      • Verify that min <= max, provide a descriptive error message otherwise.

3 - Complete the Decision Structures Exercises in a separate program. Test them to ensure that they work.

4 - Create a program called Part 5 - Console Decisions as described in Decision Structures Assignments.

SUBMIT

    • The program Part 5 - Console Decisions as described Decision Structures Assignments.

        • Simple Banking Machine, Parking Garage and Hurricane all need to be included. Please put each part into its own static method. For full marks, use a menu to allow me to select which part to run.

        • All programs need to provide clear prompts so that the user knows exactly what they are expected to type.

        • All programs should include error checking so that non-valid input does not generate an exception and appropriate error messages are displayed.

DecisionStructures.pdf

Decision Structures Exercises

Solutions: https://github.com/AldworthClass/If-Exercises-4U

Decision Structures Exercises.pdf

Decision Structures Assignments

Decision Structures Assignments.pdf

Files

Hints/Tips/FAQ

Q: My if statement is always executing the body of the if statement, even though I KNOW the condition is false.

A: The most likley cause of this is accidentily adding a semicolon (;) right after the conditional part of the if statement like this:

if (any conditional statement); // the semicolon here ends the if block

{

// You may think this is in if block, but it is not, it will always be run

}