Exemplo n.º 1
0
        public static void Main()
        {
            while (true)
            {
                Console.WriteLine("\nInterest Calculators");
                Console.WriteLine("1. Simple interest");
                Console.WriteLine("2. Compound Interest");
                Console.WriteLine("3. Quit");
                var option = OnlyMathLib.RequireValidDecimal("\nOption: ");

                switch (option)
                {
                case 1:
                    CalculateSimpleInterest();
                    break;

                case 2:
                    CalculateCompoundInterest();
                    break;

                case 3:
                    Environment.Exit(0);
                    break;

                default:
                    continue;
                }
            }
        }
Exemplo n.º 2
0
        public static void Main()
        {
            decimal change     = 0;
            decimal baseAmount = 0;

            while (true)
            {
                Console.WriteLine("\nPercent Change");
                Console.WriteLine("1. Enter change and base amount");
                Console.WriteLine("2. Enter new amount and old amount");
                Console.WriteLine("3. Enter percentage of change");
                Console.WriteLine("4. Quit");
                var option = RequireValidDecimal("\nOption: ");

                if (option < 1 || option > 4)
                {
                    continue;
                }

                if (option == 4)
                {
                    Environment.Exit(0);
                }

                if (option == 1)
                {
                    change     = RequireValidDecimal("Enter amount of change: ");
                    baseAmount = RequireValidDecimal("Enter base amount: ");

                    Console.WriteLine();
                    var percentChange = PercentChange(change, baseAmount);
                    OnlyMathLib.ColorWriteLine($"{baseAmount + change} is an increase of {percentChange * 100:N2}% from {baseAmount}");
                    OnlyMathLib.ColorWriteLine($"{baseAmount - change} is a decrease of {percentChange * 100:N2}% from {baseAmount}");
                }

                if (option == 2)
                {
                    var newAmount = RequireValidDecimal("Enter new amount: ");
                    baseAmount = RequireValidDecimal("Enter old amount: ");
                    change     = Math.Abs(newAmount - baseAmount);

                    var message = newAmount > baseAmount ? "increase" : "decrease";

                    Console.WriteLine();
                    var percentChange = PercentChange(change, baseAmount);
                    OnlyMathLib.ColorWriteLine($"{newAmount} is an {message} of {percentChange * 100:N2}% from {baseAmount}");
                }

                if (option == 3)
                {
                    baseAmount = RequireValidDecimal("Enter base amount: ");
                    var percentChange = RequireValidDecimal("Enter percent change: ");
                    change = percentChange * baseAmount / 100;

                    Console.WriteLine();
                    OnlyMathLib.ColorWriteLine($"{change + baseAmount} is an increase of {percentChange}%");
                    OnlyMathLib.ColorWriteLine($"{baseAmount - change} is a decrease of {percentChange}%");
                }
            }
        }
Exemplo n.º 3
0
        private static void CalculateSimpleInterest()
        {
            Console.WriteLine();
            var principal = OnlyMathLib.RequireValidDecimal("Principal Amount: ");
            var rate      = OnlyMathLib.RequireValidDecimal("Interest rate: ");
            var years     = OnlyMathLib.RequireValidDecimal("Years: ");

            var interest = SimpleInterest(principal, rate / 100, years);

            Console.WriteLine();
            OnlyMathLib.ColorWriteLine($"Interest: {interest:N2} Principal + Interest: {interest + principal:N2}");
        }
Exemplo n.º 4
0
        private static void CalculateCompoundInterest()
        {
            Console.WriteLine();
            var principal = OnlyMathLib.RequireValidDecimal("Principal Amount: ");
            var rate      = OnlyMathLib.RequireValidDecimal("Interest rate: ");
            var years     = OnlyMathLib.RequireValidDecimal("Years: ");
            var frequency = OnlyMathLib.RequireValidDecimal("Times compounded per year: ");

            var interest = CompoundInterest(principal, rate / 100, frequency, years);

            Console.WriteLine();
            OnlyMathLib.ColorWriteLine($"Interest: {interest:N2} Principal + Interest: {interest + principal:N2}");
        }