alex-md
10/29/2016 - 2:12 AM

Determines hourly wage based on salary and hours worked per week

Determines hourly wage based on salary and hours worked per week

using System;

namespace LoopSum
{
    class hourlyWageCalc
    {
        static void Main()
        {
            double hoursWorked;
            double yearlyIncome;
            double hourlyWage;
            bool loopProgram;

            Console.BackgroundColor = ConsoleColor.White;
            Console.ForegroundColor = ConsoleColor.Black;
            Console.Clear();

            hoursWorked = GetHoursWorked();
            yearlyIncome = GetSalary();
            hourlyWage = PerformCalculation(hoursWorked, yearlyIncome);
            DisplayHourlyWage(hourlyWage);
            loopProgram = GoAgain();
            if (loopProgram == true)
            {
                Console.Clear();
                hoursWorked = GetHoursWorked();
                yearlyIncome = GetSalary();
                hourlyWage = PerformCalculation(hoursWorked, yearlyIncome);
                DisplayHourlyWage(hourlyWage);
                loopProgram = GoAgain();
            }

            CloseProgram();
        }

        private static bool GoAgain()
        {
            string loopProgram;
            Console.Write("\n\n\t\tWould you like to go again? <Y or N>: ");
            loopProgram = Console.ReadLine();
            if (loopProgram.ToUpper() == "Y")
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        private static double GetHoursWorked()
        {
            double hoursWorked;
            Console.Write("\n\n\t\tPlease enter the number of hours you work per week: ");
            hoursWorked = Convert.ToDouble(Console.ReadLine());
            return hoursWorked;
        }

        private static double GetSalary()
        {
            double yearlyIncome;
            Console.Write("\t\tPlease enter your estimated yearly income: ");
            yearlyIncome = Convert.ToDouble(Console.ReadLine());
            return yearlyIncome;
        }

        private static double PerformCalculation(double hoursWorked, double yearlyIncome)
        {
            double hourlyWage;
            hourlyWage = yearlyIncome / (hoursWorked * 52);
            return hourlyWage;
        }

        private static void DisplayHourlyWage(double hourlyWage)
        {
            Console.Write("\n\t\tYour estimated hourly wage is ");
            Console.ForegroundColor = ConsoleColor.Red;
            Console.Write("{0:C2}", hourlyWage);
            Console.ForegroundColor = ConsoleColor.Black;
        }

        private static void CloseProgram()
        {
            Console.Write("\n\t\tPress any key to continue... ");
            Console.ReadKey();
        }
    }
}