Can someone help with this program?

I'm writing a program that takes an integer input as a dollar amount and the program will then tell you the fewest bills possible to get to that amount. My assignment was to use a function, but I can't figure out why this program is only outputting zeros. Thanks for any help for this beginner!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
  #include <iostream>
using namespace std;

int bills, total;

int hundreds = 0;
int fifties = 0;
int twenties = 0;
int tens = 0;
int fives = 0;
int ones = 0;

//function prototype
void change(int total, int hundreds, int fifties, int twenties, int tens, int fives, int ones);


int main()
{
    //ask user for the amount of money
    cout << "Enter the total amount of money as an integer: ";
    cin  >> total;

    //call the change function
    change(total, hundreds, fifties, twenties, tens, fives, ones);

    //output the number of bills
    cout << "Number of hundred dollar bills: " << hundreds << endl;
    cout << "Number of fifty dollar bills: " << fifties << endl;
    cout << "Number of twenty dollar bills: " << twenties << endl;
    cout << "Number of ten dollar bills: " << tens << endl;
    cout << "Number of five dollar bills: " << fives << endl;
    cout << "Number of one dollar bills: " << ones << endl;

    return 0;
}

//change function
void change(int total, int hundreds, int fifties, int twenties, int tens, int fives, int ones)
{
    while (total >= 100)
    {
        total -= 100;
        hundreds += 1;
    }

    while (total >= 50)
    {
        total -= 50;
        fifties += 1;
    }

    while (total >= 20)
    {
        total -= 20;
        twenties += 1;
    }

    while (total >= 10)
    {
        total -= 10;
        tens += 1;
    }

    while (total >= 5)
    {
        total -= 5;
        fives += 1;
    }

    while (total >= 1)
    {
        total -= 1;
        ones += 1;
    }
}
Your results are 0's because you are never even changing the variables you are passing in. There are two ways to solve this.
One way: Pass in the local variables by reference(&) rather than by value, which clears up some global vars.
2nd way: You already made global variables up above and well the ones you are passing into the function are useless and only causing ambiguity. Simply remove all the parameters in change and only keep total and its solved.

NOTE: I noticed a logical problem in your change function but that is for you to solve. Unless you need us to point it out.
Thank you! That cleared it up!
Topic archived. No new replies allowed.