C# Lesson 11

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!

C# Lesson 7

You're familiar with "while" loops in C#, but but it's time to learn about "for" loops. Let's get loopy in the 7th lesson in our series about learning C#.

C# Lesson 5

Run sections of your code only IF you want them to with the "if" statement in the 5th lesson from the series on learning C# for beginners.

C# Lesson 3

Learn how to do some basic math with C# in the 3rd lesson from our series for beginners learning C#.

C# Lesson 4

You truly need this lesson from our beginner series if you aren't familiar with using a Boolean in C#.

Comments

Log in or sign up to leave a comment.