import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("请输入成本");
double chengben = sc.nextDouble();
System.out.println("请输入贴现率");
double rate = sc.nextDouble();
System.out.println("请输入年限");
int year = sc.nextInt();
//定义一个数组
double[] flows = new double[year];
for (int i = 0; i < year; i++) {
System.out.println("请输入第" + (i + 1) + "年的钱");
flows[i] = sc.nextDouble();
}
double npy = 0;
npy = npvjisuan(chengben, flows, rate, year);
double originalValue = npy; // 需要四舍五入的原始值
double roundedValue = Math.round(originalValue * 100.0) / 100.0; // 进行四舍五入并保留两位小数
System.out.println(roundedValue);
}
public static double npvjisuan(double chengben, double[] liu, double rate, int year) {
double npv = chengben;
for (int i = 0; i < year; i++) {
npv += liu[i] / Math.pow(1.0 + rate, i + 1);
}
return npv;
}
}