C++ examples for Function:Function Creation
Create function that determines the area of a rectangle by multiplying its length by its width
#include <iostream> /*from w w w . j a va 2s . c om*/ int findArea(int length, int width); // function prototype int main() { int length; int width; int area; std::cout << "\nHow wide is your yard? "; std::cin >> width; std::cout << "\nHow long is your yard? "; std::cin >> length; area = findArea(length, width); std::cout << "\nYour yard is "; std::cout << area; std::cout << " square feet\n\n"; return 0; } // function definition int findArea(int l, int w) { return l * w; }