C# Lesson 11

blog post header image

Lesson 11 in our series about learning C# teaches you about working with using boolean operators to control logic flow.

Learn how to use Boolean operators instead of nested If statements.
Afterwards you can continue to the next lesson!
Or go back and review the previous lesson.
We also have the source code on GitHub.


using System;

namespace Lesson11
{
    class BooleanOperators
    {
        static void Main(string[] args)
        {
            // && - AND
            // || - OR
            // !  - NOT 

            Console.WriteLine("Enter 3 numbers:");
            Console.Write("1: ");
            int number1 = Convert.ToInt32(Console.ReadLine());

            Console.WriteLine();
            Console.Write("2: ");
            int number2 = Convert.ToInt32(Console.ReadLine());

            Console.WriteLine();
            Console.Write("3: ");
            int number3 = Convert.ToInt32(Console.ReadLine());

            Console.WriteLine();
            Console.WriteLine($"{number1}-{number2}-{number3}");

            if (number1 == 0 || number1 > number2 && number1 > number3)
            {
                Console.WriteLine(number1);
            }
            else if (number2 > number1 && number2 > number3 || number2 == 0)
            {
                Console.WriteLine(number2);
            }
            else if (number3 > number1 && number3 > number2 || number3 == 0)
            {
                Console.WriteLine(number3);
            }


        }
    }
}


/*
* TASK2:
*   Make a program asks the user to enter a SAT and ACT test scores.
*   Then ask for the person's Net worth.
*   
*   If the SAT score is above 1800 and the ACT score is above 25 they 
*   will get accepted into the school.
*   
*   But, if their Net worth is > $1,000,000 they will be accepted into
*   the school regardless of their scores.
*   
*   
*   Example Output:
*   
    *   Enter SAT score: 1801
    *   Enter ACT score: 26
    *   Enter Net worth: 5.00
    *   
    *   YOU ARE ACCEPTED!!
*   
*   Example Output:
*   
    *   Enter SAT score: 170
    *   Enter ACT score: 20
    *   Enter Net worth: 5000000.00
    *   
    *   YOU ARE ACCEPTED!!
*   
*   Example Output:
*   
    *   Enter SAT score: 170
    *   Enter ACT score: 20
    *   Enter Net worth: 5.00
    *   
    *   You are not accepted...
*   
*   
*/

using System;

namespace Lesson11Task
{
    class BooleanOperatorsTask
    {
        static void Main(string[] args)
        {
        }
    }
}

Recommended posts

We have similar articles. Keep reading!