作业要求:编写程序,估计一个职员在65岁退休之前能赚到多少钱。用年龄和超始薪水作为输入,并假设职员每年工资增长5%。
作业代码:
Console.WriteLine("输入年龄");
string str_year = Console.ReadLine();
Console.WriteLine("输入始薪");
string str_money = Console.ReadLine();
try
{
int year = Convert.ToInt32(str_year);
double money = Convert.ToInt32(str_money);
double mon = money;
while (year <= 65)
{
money *= 1.05;
mon += money;
year++;
}
Console.WriteLine("你的总工资{0}",mon);
}
catch
{
Console.WriteLine("格式输入错误");
}
Console.ReadKey();
作业效果:
1.png
1.png