1st Console App in .NET

When I teach people .NET Console Apps with C# here is my first program.


using System;
using Microsoft.VisualBasic;

namespace CharlesHelloWorld
{
    class LoanCalc
    {
        static void Main(string[] args)
        {
            try
            {

                // Ask Their Name
                Console.WriteLine("Hello");
                Console.WriteLine("What is Your Name?");
                string strNameOfPerson = Console.ReadLine();

                // Greet Them 
                string strGreeting = "Hello " + strNameOfPerson + " it is Nice to Meet You!";
                Console.BackgroundColor = ConsoleColor.Gray;
                Console.ForegroundColor = ConsoleColor.Black;
                Console.WriteLine(strGreeting);

                // Display the Time
                Console.WriteLine("The Time is " + DateTime.Now);
                Console.WriteLine();

                // Now Ask for Loan Amounts
                Console.WriteLine("Let Us Calculate a Loan for you!");
                Console.WriteLine();

                Console.WriteLine("How Much is the principal?");
                string strPrincipal = Console.ReadLine();
                double dblLoanAmount = -1 * Convert.ToDouble(strPrincipal);

                Console.WriteLine("How Much is Interest Rate?");
                string strInterestRate = Console.ReadLine();
                double dblInterestRate = Convert.ToDouble(strInterestRate);

                Console.WriteLine("How Many Years Will You Borrow The Money?");
                string strYearsBorrowed = Console.ReadLine();
                double dblYearsBorrowed = Convert.ToDouble(strYearsBorrowed);

                // Now Calculate and Display The Loan
                Double dblPayment = Financial.Pmt(dblInterestRate / 12, dblYearsBorrowed*12, dblLoanAmount, 0, DueDate.BegOfPeriod);

                Console.Beep(4000, 500);
                Console.WriteLine("Do You Want To Know how Much Is The Payment?");
                string strAnswer = Console.ReadLine();
                if (strAnswer == "Y" || strAnswer == "y" || strAnswer.ToLower() == "yes")
                {
                    string strMsg=String.Format("Your payment is {0}!",dblPayment);
                    Console.WriteLine(strMsg);
                    Console.Beep(4000, 500);
                } // end if
                else
                {
                    Console.WriteLine("I guess you will never know the payment :(");
                } // end else
                Console.ReadKey();
            } // end try
            catch (Exception exc1)
            {
                for (int counter = 1; counter < 6; counter++)
                {
                    Console.Beep(counter * 1000, 200);
                }
                Console.WriteLine("Sorry I cannot calculate that!");
                Console.WriteLine(exc1.Message);
                Console.ReadKey();
            } // end catch


        } // end Main
    } // end Class LoanCalc
} // end Namespace CharlesHelloWorld


Leave a Reply