我是C++的新手。我正在爲價值傳遞而掙扎,沒有人能以我能理解的方式解釋我對我做錯了什麼。我知道這是我的錯,但是我正在尋求我的代碼幫助。請幫助!'SalesTaxPct'未在此範圍內聲明
#include <iostream>
using namespace std;
double getValues();
double getSalesTax(double SalesTaxPct);
double gettotal_price(double base, double opt);
void PrintFinal(double base,double opt,double SalesTaxPct);
// function to control all other functions
int main()
{
getValues();
getSalesTax(SalesTaxPct);
PrintFinal(base,pt,SalesTaxPct);
}
// function to calculate sales tax percent into decimal
double getSalesTax(double SalesTaxPct)
{
double SalesTax;
SalesTax = SalesTaxPct/100;
return SalesTax;
}
// function to find total
double gettotal_price(double base, double opt, double SalesTax)
{
return = (base + opt) * (1 + SalesTax);
}
// function to show user all values input and also total
void PrintFinal(double base, double opt, double SalesTaxPct)
{
cout << "Base vehicle price: $" << base << endl;
cout << "Options Price: $" << opt << endl;
cout << "Sales tax pct: " << SalesTaxPct << "%" << endl;
cout << "Total vehicle price: $" << gettotal_price(double base, double opt, double SalesTax) << endl;
}
// function to get input values
void getValues()
{
double base, double opt, double SalesTaxPct;
cout << "Enter a base vehicle price: " << endl;
cin >> base;
cout << "Enter options price: " << endl;
cin >> opt;
cout << "Enter a sales tax percent: " << endl;
cin >> SalesTaxPct;
}
我真的很喜歡你如何將所有輸入放在一個函數中,並將所有的輸出放在另一個函數中。這使您可以將所有主邏輯放在自己的代碼中,而不必關心如何獲得結果或執行操作。有一天,您可能想從文件獲取數據或通過網絡發送數據,而唯一需要更改的是輸入/輸出代碼。 – 2012-04-26 17:19:52