C++ Tutorial/Language Basics/Expression
Версия от 14:21, 25 мая 2010; (обсуждение)
Use function in an expression
#include <iostream>
using namespace std;
double box(double length, double width, double height); // use double data
int main()
{
double sum;
sum = box(10.1, 11.2, 3.3) + box(5.5, 6.6, 7.7) + box(4.0, 5.0, 8.0);
cout << "The sum of the volumes is " << sum << "\n";
cout << "The average volume is " << sum / 3.0 << "\n";
return 0;
}
// This version of box uses double data.
double box(double length, double width, double height)
{
return length * width * height ;
}
The sum of the volumes is 812.806 The average volume is 270.935