application2-2.cpp

来自「对于特定长度的高速公路」· C++ 代码 · 共 46 行

CPP
46
字号
#include <iostream> 
#include <cmath> 
#include <iomanip> 
#include <locale> 
 
using namespace std; 
   
// Compute the future value of an investment.  
double futval(double principal, double rateOfRet, 
              int numYears, int compPerYear) {  
  double b, e; 
  
  rateOfRet /= 100.0; // convert percentage to fraction  
 
  b = (1 + rateOfRet/compPerYear); 
  e = compPerYear * numYears; 
  
  return principal * pow(b, e); 
} 
 
int main() { 
  double p, r; 
  int y, cpy; 
 
  // Set locale to English.  Adjust as necessary 
  // for your language and/or egion. 
  cout.imbue(locale("english")); 
 
  cout << "Enter principal: "; 
  cin >> p; 
 
  cout << "Enter rate of return (as a percentage): "; 
  cin >> r; 
 
  cout << "Enter number years: "; 
  cin >> y; 
 
  cout << "Enter number of compoundings per year: "; 
  cin >> cpy; 
 
  cout << "\nFuture value: " << fixed << setprecision(2) 
       << futval(p, r, y, cpy) << endl; 
 
  return 0; 
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?