【发布时间】:2014-09-27 01:46:03
【问题描述】:
我正在尝试创建一个打印函数,其中我将几段文本和从函数中获得的数值结合起来。编译时收到错误:
错误信息
error: invalid operands of types ‘const char [5]’ and ‘double (*)(double, double, double, double, double)’ to binary ‘operator+’
wrtResult = ("s = " + sortValues + " kJ/(kg.K)");
源代码
#include <iostream>
#include <cmath>
#include <string>
using namespace std;
void eqOut(double sortValues(double tempC,double xo,double yo,double xone,double yone))
{
string wrtResult;
wrtResult = ("s = " + sortValues + " kJ/(kg.K)"); // This is the line in question
cout << wrtResult;
}
int main()
{
double tempC;
double xo, xone, yo, yone;
cout << "Enter a temp in C : ";
cin >> tempC;
if ((tempC < 150) || (tempC > 500))
{
cout << "Enter a value between 150 and 500 next time!" << endl;
}
else
{
double sortValues(double tempC,double xo,double yo,double xone,double yone);
{
double temp150 = 150, temp200 = 200,
temp250 = 250, temp300 = 300,
temp400 = 400, temp500 = 500;
double ent150 = 7.2810, ent200 = 7.5081,
ent250= 7.7100, ent300 = 7.8941,
ent400 = 8.2236, ent500 = 8.5153;
double x;
if (tempC == 150)
{
cout << "7.2810 kJ/(kg.K)";
}
if (tempC > 150 && tempC < 200)
{
x = tempC;
xo = ent150;
xone = ent200;
yo = temp150;
yone = temp200;
return (yone+(yone-yo)*((x-xo)/(xone-xo)));
}
if (tempC > 200 && tempC < 250)
{
x = tempC;
xo = ent200;
xone = ent250;
yo = temp200;
yone = temp250;
return (yone+(yone-yo)*((x-xo)/(xone-xo)));
}
if ((tempC > 250) && (tempC < 300))
{
x = tempC;
xo = ent250;
xone = ent300;
yo = temp250;
yone = temp300;
return (yone+(yone-yo)*((x-xo)/(xone-xo)));
}
if ((tempC > 300) && (tempC < 400))
{
x = tempC;
xo = ent300;
xone = ent400;
yo = temp300;
yone = temp400;
return (yone+(yone-yo)*((x-xo)/(xone-xo)));
}
if ((tempC > 400) && (tempC < 500))
{
x = tempC;
xo = ent400;
xone = ent500;
yo = temp400;
yone = temp500;
return (yone+(yone-yo)*((x-xo)/(xone-xo)));
}
}
}
eqOut;
return 0;
}
【问题讨论】:
-
我不知道从哪里开始
-
你需要get a good book。
-
很糟糕吧?哎呀。我们昨天刚刚介绍了函数,所以我确定我完全误解了它们。也许我应该回到这里的绘图板并一起删除这个声明。
-
@Buttons “很糟糕吧?” 很抱歉,但是:是的!真是太糟糕了……
-
太好了,谢谢你>_