Calculates the area of a three-dimensional cube, using default function parameter values for two of the dimensions. - C++ Function

C++ examples for Function:Function Parameter

Description

Calculates the area of a three-dimensional cube, using default function parameter values for two of the dimensions.

Demo Code

#include <iostream> 
 
int findArea(int length, int width = 20, int height = 12); 
 
int main() //from  ww w . jav a  2s. co  m
{ 
    int length = 100; 
    int width = 50; 
    int height = 2; 
    int area; 
 
    area = findArea(length, width, height); 
    std::cout << "First area: " << area << "\n\n"; 
 
    area = findArea(length, width); 
    std::cout << "Second area: " << area << "\n\n"; 
 
    area = findArea(length); 
    std::cout << "Third area: " << area << "\n\n"; 
    return 0; 
} 
 
int findArea(int length, int width, int height) 
{ 
    return (length * width * height); 
}

Result


Related Tutorials