Q:

Error in a function call

Write a function NumberOfPennies() that returns the total number of pennies given a number of dollars and (optionally) a number of pennies. Ex: 5 dollars and 6 pennies returns 506. 

For the above question, here is the code below.
Getting an error: error: no matching function for call to 'NumberOfPennies(int)'
#include <iostream>
using namespace std;

int NumberOfPennies(int one,int two)
{
 return (one*100+two);
}

int main() {
cout << NumberOfPennies(5, 6) << endl; // Should print 506
cout << NumberOfPennies(4) << endl;    // Should print 400
return 0;
}

However, when I put int two=0 in the function NumberOfPennies it is working. Why is this so? Can anyone please explain this.
#include <iostream>
using namespace std;

int NumberOfPennies(int one,int two=0)
{
 return (one*100+two);
}

int main() {
cout << NumberOfPennies(5, 6) << endl; // Should print 506
cout << NumberOfPennies(4) << endl;    // Should print 400
return 0;
}

A:

The fact that you have written int two = 0 in the second snippet is your supporting a default value of that parameter two of 0.
This means that it can be omitted at the calling site with the default value assumed if it is, so
cout << NumberOfPennies(4) << endl;

and
cout << NumberOfPennies(4, 0) << endl;

are equivalent. If you don't code your function to support a default value then you need to use two arguments to call NumberOfPennies.
(In order to improve readability consider renaming your parameters one and two to dollars and cents respectively).

A:

"I ran the code below but it is not working"

is not a useful description of your problem.

Why is this so? Can anyone please explain this.

Your problem is clearly described in the compiler error report, which you should include in your post.
error: no matching function for call to ‘NumberOfPennies(int)’
          std::cout << NumberOfPennies(4)   << std::endl;
                                       ^
note: candidate: int NumberOfPennies(int, int)
    int NumberOfPennies(int one, int two)
        ^~~~~~~~~~~~~~~
note:   candidate expects 2 arguments, 1 provided

Thus, you tried to invoke the function with 1 argument, when your declaration requires 2.
By adding the default value for the second parameter, 
int NumberOfPennies(int one,int two=0) ...

You have provided a value for the second parameter when not provided.  
Review default function parameter.

