gpt4 book ai didi

c++ - 函数不接受 1 个参数 c++

转载 作者:太空宇宙 更新时间:2023-11-04 11:40:22 27 4
gpt4 key购买 nike

我的代码有问题,因为我无法弄清楚为什么会收到错误。这是代码:

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 个参数。我正在尝试运行一个函数来检查字符串的值,并在做出决定之前确定该值是什么。在这三个实例中的两个实例中,该函数调用自身再次运行,直到用户输入可接受的 double (我通过运行 0 的幂来检查答案 1。)我已将生成错误的三行加粗.有趣的是,即使注释掉函数 futureValConv 并且从不调用其他函数,我仍然会遇到三个错误中的两个。

最佳答案

你在顶部声明了这个:

bool stringChar();
bool stringVal();

所以编译器期望 stringChar 和 stringVal 函数没有参数。将声明更改为:

bool stringChar(string response);
bool stringVal(string response);

关于c++ - 函数不接受 1 个参数 c++,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21642513/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com