Write a function named moneyAmount which receives four parameter values named quarters, dimes, nickels and pennies and then calculates and returns the total amount of money represented. Demonstrate the function by calling it in a program that asks the user to enter values for the number of quarters, dimes, nickles and pennies, calls the function and then displays the returned value. include comments in the program with your name and the date.
I'v been working on this for three days non stop and I cant figure out why it's returning the wrong value. can someone please help me? My name is Nick.
using namespace std;
cout << "Enter the number of quarters: ";
cin >> quarters;
cout << "Enter the number of dimes: ";
cin >> dimes ;
cout << "Enter the number of nickles: ";
cin >> nickles ;
cout << "Enter the number of pennies: ";
cin >> pennies ;
cout << "\n";
First of all, you really should be using code tags. Second, why are you using void if you want to return a value. Void means you don't return anything. You can't have variables of the same name in another function and expect the compiler to think "Oh those are the same". You need to approach this a lot differently. Perhaps review functions a bit.
Initialise your values to 0. Otherwise any data in that block of memory may effect your program, this is standard practice.
void money() should be a float function (to pass an integer with a decimal point) and should pass back a value.
I recommend doing the input for the money in the main and doing the calculations in the function like they asked you to do in the question, it says to do the input in the program and the calculations in the function.
You need to pass the values between the main function and the money function. If you don't give the function any data how do you expect it to process it? A function can't see variables in other functions unless it's told to.
You have integer values for everything when they should be floating point which you'll need for any calculation in decimal.