DotNet-100-PreWork-GitBook
  • DotNet PreWork
  • Part 0: Intro
    • 1.0: Installation
    • 2.0: Getting Started
    • 3.0: Configuration
  • Part 1: HTML Fundamentals
    • Basic Tags
    • H & P Tags
    • Lists
    • Links
    • Images
    • Tables
    • Divs
    • Inputs
    • Forms
    • Sections
    • Articles & Headers
    • Footers
    • Navs
    • iFrames
  • Part 2: CSS Fundamentals
    • CSS Set Up
    • Classes
    • Ids
    • Margins & Padding
    • Fonts
    • Backgrounds
    • Widths & Heights
    • Borders
    • Positions
  • Part 3: C# Fundamentals
    • 1.0: Hello World
    • 2.0: Variables
    • 3.0: Basic Types
    • 3.0a: Types Challenges
    • 3.0b: Types Challenges Answers
    • 4.0: Operators
    • 5.0: Strings
    • 6.0: Booleans
      • 6.0a: Boolean Challenge
      • 6.0b: Challenge Answers
    • 7.0: Conditionals
      • 7.1: Switch Case
      • 7.2: If Statements
      • 7.3: Ternary Expressions
    • 8.0: Numbers
    • 9.0: Loops
      • 9.0a: Loop Challenges
      • 9.0b: Challenge Answers
    • 10.0: Classes and Objects
    • 11.0: Properties
    • 12.0: Useful-Links
Powered by GitBook
On this page
  • Bronze:
  • Silver:
  • Gold:
  • Discussion
  1. Part 3: C# Fundamentals
  2. 6.0: Booleans

6.0b: Challenge Answers

Bronze:

class Program
{
    static void Main(string[] args)
    {
        int value = 100 / 2;
        if (value == 50)
        {
            Console.WriteLine(true);
        }

        else
        {
            Console.WriteLine(false);
        }
    }
}

Silver:

class Program
{
    static void Main(string[] args)
    {
        double value = 101d / 2d;
        if (value == 50d)
        {
            Console.WriteLine(true);
        }

        else if (value != 50d)
        {
            Console.WriteLine(false);
        }
    }
}

Gold:

Your programs may vary a little bit but it should look something like this: 1. Print the rules of the game to the console 2. Save the user's input to the ReadLine() and use Convert.ToInt16() so the program will convert the user's input back to a string 3. Create if, else if, and else statements inputting the range the statement will use and the data the program will spit out if the statement is true. 4. Try typing if then press the tab key twice and it will scaffold out an if statement for you.

Discussion

if statements will always be run within the program. Else if statements will only be run if the previous statements were not true. Else statements will only be run if none of the other statements were true.

 class Program
{
    static void Main(string[] args)
    {
        Console.WriteLine("Can you guess what number I am thinking of? It is between 1-20");
        int guessNumber = Convert.ToInt16(Console.ReadLine());
        if (guessNumber <= 7 && guessNumber >= 1)
        {
            Console.WriteLine("You need to go much higher!");
        }
        else if (guessNumber <= 14 && guessNumber > 7)
        {
            Console.WriteLine("Little bit higher!");
        }
        else if (guessNumber == 15)
        {
            Console.WriteLine("Winner Winner Chicken Dinner!");
        }
        else if (guessNumber >= 16 && guessNumber <= 20)
        {
            Console.WriteLine("Oops, little bit lower");
        }
        else
        {
            Console.WriteLine("Did you read the instructions?");
        }
        Console.ReadLine();
    }
}
Previous6.0a: Boolean ChallengeNext7.0: Conditionals

Last updated 6 years ago

Conditionals

Next: