protos.cpp 764 B

1234567891011121314151617181920212223242526272829303132
  1. // protos.cpp -- using prototypes and function calls
  2. #include <iostream>
  3. void cheers(int); // prototype: no return value
  4. double cube(double x); // prototype: returns a double
  5. int main()
  6. {
  7. using namespace std;
  8. cheers(5); // function call
  9. cout << "Give me a number: ";
  10. double side;
  11. cin >> side;
  12. double volume = cube(side); // function call
  13. cout << "A " << side <<"-foot cube has a volume of ";
  14. cout << volume << " cubic feet.\n";
  15. cheers(cube(2)); // prototype protection at work
  16. // cin.get();
  17. // cin.get();
  18. return 0;
  19. }
  20. void cheers(int n)
  21. {
  22. using namespace std;
  23. for (int i = 0; i < n; i++)
  24. cout << "Cheers! ";
  25. cout << endl;
  26. }
  27. double cube(double x)
  28. {
  29. return x * x * x;
  30. }