-1
#include <iostream>
#include <iomanip>
using namespace std;

int main () // print to console: 3.0*5.0=15.00
{
    double a;
    double b;
    a =(3.0);
    b =(5.0);
    cout << "  " << fixed << setprecision (1) << a << "\n" << endl;
    cout << "* " << b << "\n" << endl;
    cout << "------" << endl;
    cout << fixed << setprecision (2) << a*b << "\n" << endl;

    return 0;
}

int calculate () // print to console: (7.1*8.3)-2.2=56.73
{
    double a;
    double b;
    double c;
    a = (7.1);
    b = (8.3);
    c = (2.2);
    cout << "  " << fixed << setprecision (1) << a << "\n" << endl;
    cout << "* " << b << "\n" << endl;
    cout << "- " << c << "\n" << endl;
    cout << "------" << endl;
    cout << setprecision(2) << (a*b)-c << "\n" << endl;
}
int calculation () // print to console: 3.2/(6.1*5.0)=0.10
{
    double a;
    double b;
    double c;
    a=(3.2);
    b=(6.1);
    c=(5.0);
    cout << "  " << fixed << setprecision (1) << a << "\n" << endl;
    cout << b << "*" << c << endl; //how can I use variables instead of using quotes?
    cout << "------" << endl;
    cout << setprecision(2) << a/(b*c) << "\n" << endl;

    system("PAUSE");

    return 0;
}

这个输出错误是什么意思?我如何解决它?有人请给我解释一下。我应该添加:int calculate(int a, int b, int c)

输出:

(32): error C4716: 'calculate' : must return a value
4

3 回答 3

0

您已将函数声明为返回int值但没有return声明的函数。void calculate()如果您不需要从中返回值,请尝试将声明更改为。

于 2012-09-23T01:11:49.333 回答
0

calculate函数需要返回一个值。您需要在末尾添加类似这样的内容calculate

return (a*b)-c;
于 2012-09-23T01:12:21.687 回答
0

这只是因为您的计算函数应该返回一个int 并且您的函数中没有返回。

如果你不想返回任何东西,你可以void calculate()

于 2012-09-23T01:13:48.693 回答