我是計算機專業的,我寫我的第一個代碼。代碼是計算汽車的每月支付。雖然我知道我還沒有完成,但我想看看爲什麼我沒有正確地傳遞函數。任何幫助將非常有義務!太少參數功能
#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;
}
同樣,我的錯誤是,我有太少的參數功能。謝謝!!
Ex;聲明:'findMonthlyPayment(雙&amountFinanced,雙&率,INT和年)',被稱爲'findMonthlyPayment()',結果是編譯器抱怨你沒有足夠的傳遞參數,你不是。清洗,沖洗,重複其他呼叫。那怎麼樣是不可理解的? – WhozCraig 2015-02-18 00:06:15