第六节课第三个作业(第七节课内容解答)
#编码
Console.WriteLine("输入本金");
string str_p = Console.ReadLine();
Console.WriteLine("输入利率");
string str_r = Console.ReadLine();
Console.WriteLine("输入年份");
string str_n = Console.ReadLine();
try
{
double p = Convert.ToDouble(str_p);
double r = Convert.ToDouble(str_r);
int n = Convert.ToInt32(str_n);
int i = 1;
while (i <= n)
{
p *= r+1;
Console.WriteLine("你第{0}年的钱是{1}",i,p);
i++;
}
}
catch
{
Console.WriteLine("输入错误");
}
Console.ReadKey();
#效果
![](https://img.haomeiwen.com/i14495091/1f2398e2ab0ef64c.png)