C# Lesson 5

Matt Bauer 1/13/2020

To if or not to if... Else.

The if statement is one of the most crucial commands. It allows you to control the state of your application so that sections of code only run when you want them to.


using System;

namespace Lesson5
{
    class IfStatement
    {
        static void Main(string[] args)
        {

            if (true)
            {
                Console.WriteLine("This will always be true.");
            }

            if (false)
            {
                Console.WriteLine("This will never execute");
            }

            //Console.Write("Enter x: ");
            //int x = Convert.ToInt32(Console.ReadLine());

            //Console.Write("Enter y: ");
            //int y = Convert.ToInt32(Console.ReadLine());

            //if (x > y)
            //{
            //    Console.WriteLine("x is bigger than y.");
            //}
            //else if (y > x)
            //{
            //    Console.WriteLine("y is bigger than x");
            //}
            //else
            //{
            //    Console.WriteLine("x is equal to y");
            //}


            //if (x > y)
            //{
            //    Console.WriteLine("x is bigger than y.");
            //}

            //if (y > x)
            //{
            //    Console.WriteLine("y is bigger than x");
            //}

            //if (x == y)
            //{
            //    Console.WriteLine("x is equal to y");
            //}


            Console.WriteLine("What planet are we on?");
            string planetAnswer = Console.ReadLine();

            if (planetAnswer == "Earth")
            {
                Console.WriteLine("Earth is correct!");
            }
            else
            {
                Console.WriteLine(planetAnswer + " is wrong");
            }


            Console.WriteLine("How many sides are on a cube?");
            int sidesAnswer = Convert.ToInt32(Console.ReadLine());

            if (sidesAnswer != 6)
            {
                Console.WriteLine(sidesAnswer + " is wrong");
            }
            else
            {
                Console.WriteLine("6 is correct!");
            }


            Console.WriteLine("Input a number greater than 9.0");
            double nineAnswer = Convert.ToDouble(Console.ReadLine());
            bool isCorrect = nineAnswer > 9.0;

            if (isCorrect)
            {
                Console.WriteLine(nineAnswer + " is correct!");
            }
            else
            {
                Console.WriteLine(nineAnswer + " is wrong");
            }

        }
    }
}


/*
* TASK:
*   Use console commands to ask the user a question, take their input,
*   then give feedback if the user is right or wrong.
*   
*   TIME TO THINK:
*     COUNT every CORRECT answer the user gives and tell them the number of correct answers at the end of the program.
*   
*   Make 6 questions. 
*   Make a question that uses one of the following comparison opperators to check for the correct answer.
*   Each comparison opperator must be used at least once.
*   
*   ==
*   !=
*   >
*   <
*   >=
*   <=
*   
*   If it is hard to think of a question. You can ask things like "What number is greater than 8" >
*   OR "What number is less than or equal to 8.3" <=
*   OR "Do not type Ball" !=
* 
* Example Output:
*   bla bla?
*   yes
*   bla bla?
*   no
*   bla bla?
*   3
*   bla bla?
*   ball
*   bla bla?
*   9.8
*   bla bla?
*   2
*   
*   You got 4 questions right!
*   
* BONUS POINTS:
*   Also display the number of questions they got wrong
*   EX:
*     You got 4 questions right and 2 wrong!
*  
* 
*/

using System;

namespace Lesson5Task
{
    class IfStatementTask
    {
        static void Main(string[] args)
        {
        }
    }
}