程序运行但程序中的第二个功能不打印?输出没有错误

时间:2012-09-18 05:57:05

标签: c++ visual-studio-2010

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

int main ()
{
double a;
double b;
a =(3.0);
b =(5.0);
cout << "  " << fixed << setprecision (1) << a << "\n" << endl;
cout << "* " << fixed << setprecision (1) << b << "\n" << endl;
cout << "------" << endl;
cout << fixed << setprecision (2) << a*b << "\n" << endl;
system("PAUSE");

return 0;
}

int calculate ()
{
   double a;
   double b;
   double c;
   a = (7.1);
   b = (8.3);
   c = (2.2);
   cout << fixed << setprecision(1) << endl;
   cout << "  " << fixed << setprecision (1) << a << "\n" << endl;
   cout << "* " << fixed << setprecision (1) << b << "\n" << endl;
   cout << "- " << fixed << setprecision (1) << c << "\n" << endl;
   cout << "------" << endl;
   cout << std::setprecision(2) << (a * b) - c << "\n" << std::endl;

system("PAUSE");

return 0;
}

-Visual Studio不报告任何错误,但是没有打印第二个函数(即:(a * b)-c)?

这是为什么?我是否需要添加“int calculate(int a,int b,int c)”?

1 个答案:

答案 0 :(得分:5)

你没有打电话给你,你需要用calculate ()从主叫它并在使用前有声明。

//....

int calculate();   //declaration
int main()
{
   //....
   calculate();
}

int calculate()    //implementation
{
   //....
}

这是非常基本的东西。我建议你阅读一本介绍性的C ++书。