I need help writing a default parameter for my online assignment, I have some code written but cannot figure it out. I will include the example given and I only need the <STUDENT CODE> part. Here is the problem...
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.
Sample program:
#include <iostream>
using namespace std;
<STUDENT CODE>
int main() {
cout << NumberOfPennies(5, 6) << endl; // Should print 506
cout << NumberOfPennies(4) << endl; // Should print 400
return 0;
}
I'm stuck on this same problem and I can't seem to get it either. I've tried what BoomWrx has tried and I've tried what Rafae11 suggested. Is there anyone who has a better understanding of what this problem is asking for?
#include "stdafx.h"
#include <iostream>
usingnamespace std;
// needs to be int instead of void since you are returning a value
int NumberOfPennies(int numDollars, int numPennies = 0)
{
return (numDollars * 100 + numPennies);
}
int main() {
cout << NumberOfPennies(5, 6) << endl; // Should print 506
cout << NumberOfPennies(4) << endl; // Should print 400
int x;
cin >> x;
return 0;
}