so i have been taking my c++ class for about a couple months and really had no problems till we hit functions. The other assignments with functions I eventually got, but this one is eluding me to no end. I think I am heading in the right direction, but just don't understand how to get it quite what I want to do.
Essentially whats asked is that this program takes a dollar value entered and breaks it down into the lowest combination of bills. Its in pass by reference chapter, but I'm just not getting it =( any help is much appreciated.

#include <iostream>
using namespace std;

void change(int &,int &,int &,int &,int &,int &);

int main()
{
   float dollar;
    int hundreds,fifties,twenties,tens,fives,ones;
    cout << "Enter dollar amount :\n";
    cin >> dollar;
    change(hundreds,fifties,twenties,tens,fives,ones);
    cout << "Least change of" << dollar << "is...";
    
    cout << "Hundreds :" << hundreds;
    cout << "Fifties :" << fifties;
    cout << "Twenties :" << twenties;
    cout << "Tens :" << tens;
    cout << "Fives :" << fives;
    cout << "Ones :" << ones;
    
    
    
    
    
    
    
    
}

void change(int &hundreds, int &fifties, int &twenties, int &tens, int &fives, int &ones)
{
 int dollar;
 int total;
 
 
 while(total >=0)
 hundreds = dollar/100;
 total = total - hundreds;
 fifties = dollar/50;
 total = total - fifties;
 twenties = dollar/20;
 total = total - twenties;
 tens = dollar/10;
 total = total - tens;
 fives = dollar/5;
 total = total - fives;
 ones = dollar/1;
 total = total - ones;
 
 
 
   
    return;
}

This for free..Enjoy..

#include <iostream>
using namespace std;

void change(float,float &,float &,float &,float &,float &,float &);

int main()
{
   float dollar;
    float hundreds,fifties,twenties,tens,fives,ones;
    cout << "Enter dollar amount :\n";
    cin >> dollar;
    change(dollar,hundreds,fifties,twenties,tens,fives,ones);
    cout << "Least change of" << dollar << "is...";
    
    cout << "Hundreds :" << hundreds;
    cout << "Fifties :" << fifties;
    cout << "Twenties :" << twenties;
    cout << "Tens :" << tens;
    cout << "Fives :" << fives;
    cout << "Ones :" << ones;
    
    
    
    
    
    
    
    
}

void change(float dollar,float &hundreds, float &fifties, float &twenties, float &tens, float &fives, float &ones)
{
 float total=0.0;
 
 
 while(total >=0.0)
 hundreds = dollar/100.0;
 total = total - hundreds;
 fifties = dollar/50.0;
 total = total - fifties;
 twenties = dollar/20.0;
 total = total - twenties;
 tens = dollar/10.0;
 total = total - tens;
 fives = dollar/5.0;
 total = total - fives;
 ones = dollar/1.0;
 total = total - ones;
 
 
 
   
    return;
}

This for free..Enjoy..

#include <iostream>
using namespace std;

void change(float,float &,float &,float &,float &,float &,float &);

int main()
{
   float dollar;
    float hundreds,fifties,twenties,tens,fives,ones;
    cout << "Enter dollar amount :\n";
    cin >> dollar;
    change(dollar,hundreds,fifties,twenties,tens,fives,ones);
    cout << "Least change of" << dollar << "is...";

    cout << "Hundreds :" << hundreds;
    cout << "Fifties :" << fifties;
    cout << "Twenties :" << twenties;
    cout << "Tens :" << tens;
    cout << "Fives :" << fives;
    cout << "Ones :" << ones;

}

void change(float dollar,float &hundreds, float &fifties, float &twenties, float &tens, float &fives, float &ones)
{
 float total=0.0;


 while(total >=0.0)
 hundreds = dollar/100.0;
 total = total - hundreds;
 fifties = dollar/50.0;
 total = total - fifties;
 twenties = dollar/20.0;
 total = total - twenties;
 tens = dollar/10.0;
 total = total - tens;
 fives = dollar/5.0;
 total = total - fives;
 ones = dollar/1.0;
 total = total - ones;

    return;
}

end quote.

Hmm its still doing the same thing. it shows the cout with Least change of << change << is... but it doesnt display anything else. thats the main stepping stone that can't for the life of me figure out. and on top of that after looking at my function i don't think the math would work right. so I have to redo that, but i can't figure that out until i figure out the whole displaying the functions values ....

Edited 3 Years Ago by mike_2000_17: Fixed formatting

How about this

#include <iostream>
using namespace std;

void change(float,float &,float &,float &,float &,float &,float &);

int main()
{
   float dollar;
    float hundreds,fifties,twenties,tens,fives,ones;
    cout << "Enter dollar amount :\n";
    cin >> dollar;
    change(dollar,hundreds,fifties,twenties,tens,fives,ones);
    cout << "Least change of" << dollar << "is...";
    
    cout << "Hundreds :" << hundreds;
    cout << "Fifties :" << fifties;
    cout << "Twenties :" << twenties;
    cout << "Tens :" << tens;
    cout << "Fives :" << fives;
    cout << "Ones :" << ones;
    
    
    
    
    
    
    
    
}

void change(float dollar,float &hundreds, float &fifties, float &twenties, float &tens, float &fives, float &ones)
{
 float total=0.0;
 
 
 while(total >=0.0)
 {
 hundreds = dollar/100.0;
 total = total - hundreds;
 fifties = dollar/50.0;
 total = total - fifties;
 twenties = dollar/20.0;
 total = total - twenties;
 tens = dollar/10.0;
 total = total - tens;
 fives = dollar/5.0;
 total = total - fives;
 ones = dollar/1.0;
 total = total - ones;
 
}
 
 
   
    return;
}

and no offense cikara but wouldn't i want to keep it integer division?
i could be way wrong but if i had say 150 dollars. divided by a integer 100 would get me one one hundred bill. so that im not getting decimal answers which would mean fractional bills.
and then the remaining value of 50 dollars divided by fifty int would get me one fifty bill if it was float wouldn't that throw things off with like values like 175$? or i could just be talking out of my rear and i apologize.

ahh sweets you fixed the display issue i actually see the math the function does. so kudos there :)
but its showing all the combinations of bills. I only need the lowest if that makes sense. so 150 would be one one hundred and then one fifty dollar bill no tens no ones so the least actual bills. I thought my math in the function would do that but i guess not...

while(total >=0.0)
 {
 hundreds = dollar/100.0;
 total = total - (hundreds * 100.0);
 fifties = dollar/50.0;
 total = total - (fifties * 50.0);
 twenties = dollar/20.0;
 total = total - (twenties * 20.0);
 tens = dollar/10.0;
 total = total - (tens * 10.0);
 fives = dollar/5.0;
 total = total - (fives * 5.0);
 ones = dollar/1.0;
 total = total - (ones * 1.0);

thats what i got for my function math...it seems like it would make sense. but its not working out how i figured it would. it is still showing the other values of the bills

#include <iostream>
using namespace std;

void change(float,int &,int &,int &,int &,int &,int &);

int main()
{
    float dollar;
    int hundreds,fifties,twenties,tens,fives,ones;
    cout << "Enter dollar amount :\n";
    cin >> dollar;
    change(dollar,hundreds,fifties,twenties,tens,fives,ones);
    cout << "Least change of" << dollar << "is...";
    
    cout << "Hundreds :" << hundreds;
    cout << "Fifties :" << fifties;
    cout << "Twenties :" << twenties;
    cout << "Tens :" << tens;
    cout << "Fives :" << fives;
    cout << "Ones :" << ones;
    
    
    
    
    
    
    
    
}

void change(float dollar,int &hundreds, int &fifties, int &twenties, int &tens, int &fives, int &ones)
{
 hundreds = dollar/100;
 fifties = dollar/50;

 twenties = dollar/20;
 tens = dollar/10;

 fives = dollar/5;

 ones = dollar/1;
 
 
   
    return;
}

yeah i tried changing just most the floats to int and dev yelled at me. but yours looked alot like the way i did it but whatevs its closer to working.
now it just needs to not show the least amount of change.
so if we had 125
itd show out one hundred bill
one twenty and one five zero fifties zero ones zero tens.

I'm not sure..

void change(float dollar,int &hundreds, int &fifties, int &twenties, int &tens, int &fives, int &ones)
{
   int total=0;
   hundreds=dollar/100;
   total=((int)dollar
%100);
   fifties=total/50;

   total=((int)dollar%50);
   twenties=total/20;
   
total=((int)dollar%20);
   tens=total/10;

   total=((int)dollar%10);
   fives=total/5;

   total=((int)dollar%5);
   ones=total/1;
 
  return;
}

Um..Sorry..

void change(float dollar,int &hundreds, int &fifties, int &twenties, int &tens, int &fives, int &ones)
{
   int total=0;
   hundreds=dollar/100;
   total=((int)dollar
%100);
   fifties=total/50;

   total=((int)dollar%50);
   twenties=total/25;

total=((int)dollar%25);
   tens=total/10;

   total=((int)dollar%10);
   fives=total/5;

   total=((int)dollar%5);
   ones=total/1;

  return;
}

Edited 3 Years Ago by Reverend Jim: Fixed formatting

oh thanks. it works perfect. almost

250 get 2 hundred bills and one fifty....but one ten too...so its close but thanks a bunch i will try and work with it and see what i can do.
you helped out alot amigo

yeah i posted late didn't notice the second page =\ but it works perfect! you saved my bottom. i suck at functions so i got some more learnings to go here

This article has been dead for over six months. Start a new discussion instead.