我的代码有问题,因为我无法弄清楚为什么我收到错误。这是代码:
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不带1个参数,以及futureValConv。我试图运行一个函数来检查字符串的值,并在做出决定之前确定值是什么。在这三个实例中的两个实例中,函数调用自身再次运行,直到用户输入了一个可接受的双精度数(我通过运行0的幂来检查答案为1.)我用三行加粗生成错误。有趣的是,即使通过注释函数futureValConv并且从不调用其他函数,我仍然会得到三个错误中的两个。
答案 0 :(得分:1)
你在顶部声明了这个:
bool stringChar();
bool stringVal();
因此编译器期望stringChar和stringVal函数没有参数。 将声明更改为:
bool stringChar(string response);
bool stringVal(string response);