Question #39654

Create a console program that calculates and displays a person’s annual salary over a specific number of years, starting in 2014. The user provides the:
- Starting salary
- Percentage salary increase per year
- Number of years for which to do the calculations
Also calculate and display the total income over all the years
1

Expert's answer

2014-03-17T11:43:26-0400
using System;
namespace Annual_Salary
{
    class Program
    {
        static void Main(string[] args)
        {
            double salary = 0;
            double d_pers = 0;
            int years = 0;
            do
            {
                Console.Clear();
                Console.WriteLine("Please enter starting salary");
                if (!Double.TryParse(Console.ReadLine().Replace('.', ', '), out salary) || salary <= 0)
                {
                    Console.WriteLine("Wrong input");
                }
                else
                {
                    Console.WriteLine("Please enter percentage salary increase per year:(Example -> 15%)");
                    string perstge = Console.ReadLine().Trim('%').Replace('.', ', ');
                    if (!Double.TryParse(perstge, out d_pers) || d_pers <= 0)
                    {
                        Console.WriteLine("Wrong input");
                    }
                    else
                    {
                        Console.WriteLine("Please enter the number of years for which to do the calculations:(integer)");
                        if (Int32.TryParse(Console.ReadLine().Replace('.', ', '), out years) || years <= 0)
                        {
                            Console.WriteLine("Starting salary: {0,12:###,##.##}$", salary);
                            for (int i = 1; i <= years; i++)
                            {
                                salary *= (d_pers / 100 + 1);
                                Console.WriteLine(" {0}: {1,12:###,##.##}$", DateTime.Today.Year + i, salary);
                            }
                        }
                        else
                        {
                            Console.WriteLine("Wrong input");
                        }
                    }
                }
                Console.Write("Press any key to continue or ESC to EXIT...");
                if (Console.ReadKey().Key == ConsoleKey.Escape) Environment.Exit(0);
            } while (true);
        }
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!
LATEST TUTORIALS
APPROVED BY CLIENTS