Help with default parameter value

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;
}




Here is what I have but is not correct.
1
2
3
4
5
6
7
8
9
10
11
  void NumberOfPennies(int numDollars; int numPennies = 0){
    
    if( numPennies == 0) {
        cout << numDollars * numPennies;
        
    }
}
return;
}

NumDollar must be multiplied by 100 and then add numpennies
 
return (NumDollar * 100 + numpennies);
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?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include "stdafx.h"

#include <iostream>
using namespace 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;
}
Topic archived. No new replies allowed.