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.
Make sure you understand the difference between multiple if statements and else if statements.
Here is another explanation of if/else if/else statements:
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.
Solutions can be found here: https://github.com/AldworthClass/If-Exercises-4U
Most of these problems have more than one solution. You don't have to have the same as me.
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.
Decision Structures Exercises
Decision Structures Assignments
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
}