Need help: Adding value of an int variable between functions.

I have been messing with my code all day and I cannot seem to figure out why it is outputting what it is. The program is suppose to add a certain amount to an int variable in one function and store it in another func, but it isnt working. Please help!
Here is my code:

#include <iostream>
#include <iomanip>
using namespace std;

void normalizeMoney(float& dollars, int cents = 150);
// This function takes cents as an integer and converts it to dollars
// and cents. The default value for cents is 150 which is converted
// to 1.50 and stored in dollars

int main() {

int cents;
float dollars;

cout << setprecision(2) << fixed << showpoint;
cents = 95;
cout << "\n We will now add 95 cents to our dollar total\n";
// Fill in the code to call normalizeMoney to add 95 cents
normalizeMoney(dollars, cents);
cout << "Converting cents to dollars resulted in $" << dollars
<< " dollars\n";
cout << "\n We will now add 193 cents to our dollar total\n";
// Fill in the code to call normalizeMoney to add 193 cents
normalizeMoney(dollars, cents + 193);
cout << "Converting cents to dollars resulted in " << dollars
<< " dollars\n";
cout << "\n We will now add the default value to our dollar total\n";
// Fill in the code to call normalizeMoney to add the default value of cents
normalizeMoney(dollars, cents + 150);
cout << "Converting cents to dollars resulted in " << dollars
<< " dollars\n";

return 0;
}void normalizeMoney(float& dollars, int cents) {

float total = 0;

// Fill in the definition of sum as a static local variable
static float sum = 0.0;

// Fill in the code to convert cents to dollars
dollars = cents / 100;
total = total + dollars;
sum = sum + dollars;
cout << "We have added another $" << dollars << " to our total" << endl;
cout << "Our total so far is $" << sum << endl;
cout << "The value of our local variable total is $" << total << endl;
}


and this is what it is outputting:
We will now add 95 cents to our dollar total
We have added another $0.00 to our total
Our total so far is $0.00
The value of our local variable total is $0.00
Converting cents to dollars resulted in 0.00 dollars

We will now add 193 cents to our dollar total
We have added another $2.00 to our total
Our total so far is $2.00
The value of our local variable total is $2.00
Converting cents to dollars resulted in 2.00 dollars

We will now add the default value to our dollar total
We have added another $2.00 to our total
Our total so far is $4.00
The value of our local variable total is $2.00
Converting cents to dollars resulted in 2.00 dollars
Please use code tags. http://www.cplusplus.com/articles/jEywvCM9/
You can edit your post, highlight your code and click the <> button on the right.

dollars = cents / 100;
As cents and 100 are both integers, dividing them will yield an integer, effectively truncating the fractional part. To get a floating point value, simply convert one of them to a float/double.
dollars = cents / 100.0f;
Topic archived. No new replies allowed.