函数不需要1个参数c ++ [英] function does not take 1 arguments c++
问题描述
我的代码存在问题,因为我无法弄清楚为什么我收到错误。这里是代码:
using namespace std;
void presentValue();
bool stringChar();
bool stringVal();
double futureValConv();
int main()
{
cout<< 欢迎使用现值利息计算器!\\\\首先,让我收集一些数据。<< endl<< endl;
presentValue();
return 0;
$ b $ void presentValue()
{
//声明变量
//响应初始化为x,用于调试
char响应= 'x';
while(response!='n'|| response!='N')
{
//声明变量
double intRate = 0 ;
string futureValString;
double futureVal;
double year = 0;
//简单现值方程
double presentVal = futureVal / pow(( intRate + 1),年);
cout<<你的利率是多少? ;
cin>> intRate;
cout<<确定,您期望的未来值是什么? [H} elp;
cin>> futureVal;
//运行递减帮助程序,不允许没有双值转义
** futureVal = futureValConv(futureValString); **
cout <<< lt lt endl lt lt endl <<最后,您想节省多少钱? ;
cin>>年;
cout<< endl<<您已经做到了这一点!!!;
cout<< endl << endl< presentVal;
}
}
inline double futureValConv(string somestring)
{
// delcare变量
double newString = 0;
** if(stringChar(somestring))**
{
cout< endl<<未来值是您希望将来在您的账户中拥有的金额。@ $ n;
cout<<这可能是多少? ;
cin>> somestring;
futureValConv(somestring);
** else if(stringVal(somestring))**
{
//将未来价值字符串转换为未来使用的双倍
newString = atoi(somestring.c_str());
}
else
{
cout<<请输入一个合适的值。 ;
futureValConv(somestring);
}
return newString;
}
bool stringChar(字符串响应)
{
//声明变量
char answer = response [0];
bool status = false;
if(answer =='H'|| answer = ='h')
{
status = true;
返回状态;
}
}
bool stringVal(字符串响应)
// 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。我试图运行一个函数检查一个字符串的值,并在做出决定之前确定它的值。实例中,函数调用自己再次运行,直到用户输入一个可接受的double(我通过运行0的幂来检查1的回答来检查)。我用粗体显示了产生错误的三条线。有趣的是,即使通过注释函数futureValConv并且从不调用其他函数,我仍然会得到两个错误。
>你在顶部声明: bool stringChar();
bool stringVal();
所以编译器期望stringChar和stringVal函数没有参数。
将声明更改为:
bool stringChar(string response);
bool stringVal(string response);
I'm having issue with my code, in that I can't figure out why I'm receiving an error. Here is the code:
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;
}
}
I posted most of my code because I can't grasp what is going on here. It is telling me that stringChar and stringVal do not take 1 arguments, as well as futureValConv. I am attempting to run a function checking the value of a string, and determining what the value is before making a decision. In two of the three instances, the function calls itself to run again until the user has entered an acceptable double (Which I check by running to the power of 0 for a an answer of 1.) I have bolded the three lines generating an error. Interestingly, even by commenting out the function futureValConv and never calling into the other functions, I still get two of the three errors.
You declared this at the top:
bool stringChar();
bool stringVal();
So the compiler expects stringChar and stringVal functions to have no arguments. Change the declaration to:
bool stringChar(string response);
bool stringVal(string response);
这篇关于函数不需要1个参数c ++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!