为什么我得到“功能论证太少”?

时间:2015-02-17 23:39:41

标签: c++ function

代码是计算汽车的每月付款。虽然我知道我没有完成,但我希望看到为什么我没有正确传递函数。

#include <iostream>
#include <string>
#include <math.h>

using namespace std;


void instructions()
{
  cout << "We will calculate the monthly payment for your particular car." << endl;
  cout << "Please Follow the instructions." << endl;
}



string getCarType()
{
  string carType;

  cout << "Please enter the type of your car: " << endl;
  cin >> carType;

  return carType;
}




double getPurchasePrice()
{
  double purchasePrice;

  cout << "Please enter the price in which you purchased the vehicle: " << endl;
  cin >> purchasePrice;

  return purchasePrice;
}




double getDownPayment()
{
  double downPayment;

  cout << "Please enter the down payment made on the vehicle: " << endl;
  cin >> downPayment;

  return downPayment;
}




int getYears()
{
  int years;

  cout << "Please enter the number of years remaining to pay off the loan: " << endl;
  cin >> years;

  return years;
}





double getRate()
{
  double rate;
  double correctedRate;

  cout << "Please enter the annual interest rate of the loan as a whole number: " << endl;
  cin >> rate;

  //calculations
  correctedRate = (rate/100);


  return correctedRate;
}





double findAmountFinanced(double &purchasePrice, double &downPayment)
{
  double amountFinanced;

  //calculations
  amountFinanced = purchasePrice - downPayment;

  return amountFinanced;
}





double findMonthlyPayment(double &amountFinanced, double &rate, int &years)
{
  double monthlyPayment;
  double sideOne;
  double sideTwo;

  //calculations
  sideOne = amountFinanced * (rate/12);
  sideTwo = pow(1 - (1 + (rate/12)) / (-12*years));
    monthlyPayment = sideOne/sideTwo;


  return monthlyPayment;
}




int findNumberOfPayments(int &years)
{
  int payments;
  payments = 12 * years;

  return payments;
}


int main()
{
  instructions();

  string carType;
  double purchasePrice;
  double downPayment;
  int years;
  double rate;
  double amountFinanced;
  double monthlyPayment;
  int payments;

  carType = getCarType();
  purchasePrice = getPurchasePrice();
  downPayment = getDownPayment();
  years = getYears();
  rate = getRate();
  monthlyPayment = findMonthlyPayment();
  payments = findNumberOfPayments();

  cout << "Make of car: " << carType  << endl;
  cout << "Price Purchased at: " << purchasePrice << endl;
  cout << "Down payment made at purchase: " << downPayment << endl;
  cout << "Years to pay off loan: " << years << endl;
  cout << "Annual rate of interest: " << rate << endl;
  cout << "Your monthly payment is: " << monthlyPayment << endl;
  cout << "The total amount of payments is: " << payments << endl;
  return 0;
}

同样,我的错误是我的参数太少了。

3 个答案:

答案 0 :(得分:1)

在某些功能中,例如 findMonthlyPayment ,您不会从main传递参数,而这些函数需要参数。你的错误是不言自明的,你应该自己调试它。

答案 1 :(得分:0)

如果查看findAmountFinanced,findMonthlyPayment和findNumberOfPayments的方法定义,它们会在调用它们时接受参数。在你调用它们的main()函数中,你没有传递任何参数。因此,论点太少了:))

仅供参考,解决问题的一个技巧是查看错误消息的完整堆栈跟踪,并按行号向下工作。

答案 2 :(得分:0)

是的,当你调用某个方法并且该方法有X个参数或参数时,每当你在程序中调用该函数时,你需要使用完全相同数量的参数和参数类型来调用它。