C# Lesson 3

Matt Bauer 1/8/2020

We are going to learn how to do some basic math with programing.

In Lesson 3 we will learn how to do math with ints and doubles.


using System;

namespace Lesson3
{
    class DoingMath
    {
        static void Main(string[] args)
        {

            //***********
            //Console.Write("Enter an Int : ");
            //int int1 = Convert.ToInt32(Console.ReadLine());

            //Console.Write("Enter another Int: ");
            //int int2 = Convert.ToInt32(Console.ReadLine());

            ////Console.WriteLine(int1 + " * " + int2 + " = " + int1 * int2); // 4, 2
            ////Console.WriteLine(int1 + " + " + int2 + " = " + int1 + int2);

            ////Console.WriteLine(int1 + " * " + int2 + " = " + (int1 * int2));
            ////Console.WriteLine(int1 + " + " + int2 + " = " + (int1 + int2));

            //Console.WriteLine(int1 + " / " + int2 + " = " + (int1 / int2));
            //Console.WriteLine(int2 + " / " + int1 + " = " + (int2 / int1));
            //Console.WriteLine(int2 + " / " + int1 + " = " + (int2 / (double)int1)); // Downcasting or Explicit Cast
            //Console.WriteLine(int2 + " / " + int1 + " = " + ((double)int2 / int1)); // Downcasting or Explicit Cast
            //***********

            //***********
            Console.Write("Enter a Double: ");
            double double1 = Convert.ToDouble(Console.ReadLine());

            Console.Write("Enter another Double: ");
            double double2 = Convert.ToDouble(Console.ReadLine());

            Console.WriteLine(double1 + " / " + double2 + " = " + (double1 / double2)); // 4, 2
            Console.WriteLine(double2 + " / " + double1 + " = " + (double2 / double1)); // .4, .2

            Console.WriteLine(double1 + " + " + double2 + " = " + (double1 + double2));
            Console.WriteLine(double1 + " - " + double2 + " = " + (double1 - double2));
            // Computer isn't able to represent some numbers accuratly.
            // The same way that .33 + .33 + .33 != 1

            double addResult = double1 + double2;// .6000000000001
            double roundedResult = Math.Round(addResult, 1);

            Console.WriteLine(double1 + " + " + double2 + " = " + roundedResult);
        }
    }
}

/*
* TASK:
* Create a program that calculates an employees' pay.
* Ask for their Employee ID. This value will always be an INT.
* Ask for the number of hours they worked.
* Ask for their hourly pay rate.
* 
* Example Output
*      Enter employee ID: 1154856
*      Enter hours worked: 16.55
*      Enter hourly pay: 12.77
*      Employee 1154856, you have earned $211.34‬
* 
*/

using System;

namespace Lesson3Task
{
    class DoingMathTask
    {
        static void Main(string[] args)
        {
            //NOTE: You will need to use convert.

            //Step 1: Ask for the employee ID. Store the input from the user into an int variable.

            //Step 2: Ask for the number of hours they worked.

            //Step 3: Ask for their hourly pay.

            //Step 4: Multiply hours by pay.

            //Step 5: Round the result to 2 decimal places.

            //Step 6: Display the result to the user.

        }
    }
}