//編寫程序:估計一個職員在665歲退休之前能賺到多少錢聋迎。用年齡和初始薪水作為輸入脂矫,并假設(shè)職員每年工資增長5%
?/**循環(huán)條件:小于等于65
?* 循環(huán)體:工資之和,每年增加5%
* */
Console.WriteLine("請輸入你現(xiàn)在的工資");
string str_salar = Console.ReadLine();
Console.WriteLine("請輸入你的年齡");
string str_age = Console.ReadLine();
double salar = 0;
int age = 0;
double sum = salar;
?bool flag = true;
try
?{
?salar = Convert.ToDouble(str_salar);
?age = Convert.ToInt32(str_age);
?flag = true;
}
catch
{
Console.WriteLine("你輸入的格式錯誤");
?flag = false;
}
?if (flag)
{
?while (age <= 65)
?{
salar *= 1.05;
sum += salar;
age++;
?}
Console.WriteLine("你到65歲退休之前的工資之和是:{0}",sum);
?}
Console.WriteLine("程序執(zhí)行完畢");
?Console.ReadKey();