#作業(yè)要求
編寫程序,估計一個職員在65歲退休之前能賺到多少錢。用年齡和起始薪水作為輸入,并假設職員每年工資增長5%。
#代碼
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
? ? class Program
? ? {
? ? ? ? static void Main(string[] args)
? ? ? ? {
? ? ? ? ? ? Console.WriteLine("請輸入你的年齡");
? ? ? ? ? ? string str_age = Console.ReadLine();
? ? ? ? ? ? Console.WriteLine("請輸入你現在的工資");
? ? ? ? ? ? string str_salar = Console.ReadLine();
? ? ? ? ? ? try
? ? ? ? ? ? {
? ? ? ? ? ? ? ? int age = Convert.ToInt32(str_age);
? ? ? ? ? ? ? ? double salar = Convert.ToDouble(str_salar);
? ? ? ? ? ? ? ? double money = salar;? ? ? ? ? //工資和
? ? ? ? ? ? ? ? while (age < 65)
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? salar *= 1.05;
? ? ? ? ? ? ? ? ? ? money += salar;
? ? ? ? ? ? ? ? ? ? age++;
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? Console.WriteLine("你到65歲時,可以領到{0}元",money);
? ? ? ? ? ? }
? ? ? ? ? ? catch
? ? ? ? ? ? {
? ? ? ? ? ? ? ? Console.WriteLine("格式輸入錯誤");
? ? ? ? ? ? }
? ? ? ? ? ? Console.ReadKey();
? ? ? ? }
? ? }
}
#效果
