Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a function NumberOfPennies() that returns the total number of pennies give

ID: 3768200 • Letter: W

Question

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.

Here is the template of the problem, please use it:

#include <iostream>
using namespace std;

double NumberOfPennies (double dollars, double Pennies)
{
double TotalPennies = dollars * 100 + Pennies;
return TotalPennies;
}

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

You just need to fill in the line with your solution goes here in the template. I have tried different options but none of them were correct. Please explain why your code is chosen. Thanks!

Explanation / Answer

PROGRAM:

#include <iostream>
using namespace std;
double NumberOfPennies (double dollars, double Pennies)
{
double TotalPennies = dollars * 100 + Pennies;
return TotalPennies;
}
double NumberOfPennies (double dollars)
{
double TotalPennies = dollars * 100 ;
return TotalPennies;
}
int main() {
cout << NumberOfPennies(5, 6) << endl; // Should print 506
cout << NumberOfPennies(4) << endl; // Should print 400
return 0;
}

OUTPUT:

REASON:

In your code there is no method with single paramater when only dollars are given.So add another function NumberOfPennies.Then due to method overloading code works fine.