Fix the Program

Fix the program

This program is supposed to output the area of a rectangle, but it isn't compiling.

Use your knowledge to find the problem and make the program compile.

#include <iostream>

double calculateArea(int w, int h);

int main() 
{
    std::cout << "Rectangle area (5 x 10): " << calculateArea(5.0, 10.0) << "\n";
}

// Function definitions with correct signatures
double calculateArea(double width, double height) 
{
    return width * height;
}

Hint

There is a missmatch between the function signatures in the declarations and definitions.

Answer

#include <iostream>

double calculateArea(double w, double h);

int main() 
{
    std::cout << "Rectangle area (5 x 10): " << calculateArea(5.0, 10.0) << "\n";
}

// Function definitions with correct signatures
double calculateArea(double width, double height) 
{
    return width * height;
}

The datatypes of the parameters were changed for the function declaration to be double. Now that both calculateArea parameter and return-types match, their signature are the same

Note that the names of the parameters are not the same. Parameter names are not part of a functions signature.

Questions