[英]function does not take 1 arguments c++
我的代碼有問題,因為我不知道為什么會收到錯誤。 這是代碼:
using namespace std;
void presentValue();
bool stringChar();
bool stringVal();
double futureValConv();
int main()
{
cout << "Welcome to the Present Value Interest Calculator!\n\"First, let me collect some data." << endl << endl;
presentValue();
return 0;
}
void presentValue()
{
//declare variables
//Response value intialized as x for debugging
char response = 'x';
while (response != 'n' || response != 'N')
{
//declare variables
double intRate = 0;
string futureValString;
double futureVal;
double years = 0;
//Simple present value equation
double presentVal = futureVal / pow((intRate + 1), years);
cout << "What's your Interest Rate? ";
cin >> intRate;
cout << "OK, and what's your desired Future Value? [H}elp ";
cin >> futureVal;
//Run descending help program that won't allow escape without a double value
**futureVal = futureValConv(futureValString);**
cout << endl << endl << "And finally, how many years would you like to save your money for? ";
cin >> years;
cout << endl << "You've made it this far!!!";
cout << endl << endl << presentVal;
}
}
inline double futureValConv(string somestring)
{
//delcare variables
double newString = 0;
**if (stringChar(somestring))**
{
cout << endl << "Future Value is the amount you would like to have in your account in the future.\n\n";
cout << "How much might that be? ";
cin >> somestring;
futureValConv(somestring);
}
**else if(stringVal(somestring))**
{
//Convert the Future Value String to a double for future use
newString = atoi(somestring.c_str());
}
else
{
cout << "Please enter a proper value. ";
futureValConv(somestring);
}
return newString;
}
bool stringChar(string response)
{
//declare variables
char answer = response[0];
bool status = false;
if (answer == 'H' || answer == 'h')
{
status = true;
return status;
}
}
bool stringVal(string response)
{
//declare varialbes
int answer = atoi(response.c_str());
bool status = false;
int powZero = (answer, 0);
if (powZero == 1)
{
status = true;
return status;
}
}
我發布了大部分代碼,因為我無法掌握這里發生的情況。 它告訴我stringChar和stringVal以及futureValConv都沒有1個參數。 我試圖運行一個檢查字符串值的函數,並在決定之前確定該值是什么。 在這三個實例中的兩個實例中,該函數調用其自身再次運行,直到用戶輸入了可接受的雙精度(這是我通過運行到0的冪來檢查答案是否為1)。 。 有趣的是,即使通過注釋函數futureValConv且從不調用其他函數,我仍然會遇到三個錯誤中的兩個。
您在頂部聲明了這一點:
bool stringChar();
bool stringVal();
因此,編譯器期望stringChar和stringVal函數沒有參數。 將聲明更改為:
bool stringChar(string response);
bool stringVal(string response);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.