Change fucntion homework help.

Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Dec 2008
Posts: 8
Reputation: brandn. is an unknown quantity at this point 
Solved Threads: 0
brandn. brandn. is offline Offline
Newbie Poster

Change fucntion homework help.

 
0
  #1
Dec 10th, 2008
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.

  1. #include <iostream>
  2. using namespace std;
  3.  
  4. void change(int &,int &,int &,int &,int &,int &);
  5.  
  6. int main()
  7. {
  8. float dollar;
  9. int hundreds,fifties,twenties,tens,fives,ones;
  10. cout << "Enter dollar amount :\n";
  11. cin >> dollar;
  12. change(hundreds,fifties,twenties,tens,fives,ones);
  13. cout << "Least change of" << dollar << "is...";
  14.  
  15. cout << "Hundreds :" << hundreds;
  16. cout << "Fifties :" << fifties;
  17. cout << "Twenties :" << twenties;
  18. cout << "Tens :" << tens;
  19. cout << "Fives :" << fives;
  20. cout << "Ones :" << ones;
  21.  
  22.  
  23.  
  24.  
  25.  
  26.  
  27.  
  28.  
  29. }
  30.  
  31. void change(int &hundreds, int &fifties, int &twenties, int &tens, int &fives, int &ones)
  32. {
  33. int dollar;
  34. int total;
  35.  
  36.  
  37. while(total >=0)
  38. hundreds = dollar/100;
  39. total = total - hundreds;
  40. fifties = dollar/50;
  41. total = total - fifties;
  42. twenties = dollar/20;
  43. total = total - twenties;
  44. tens = dollar/10;
  45. total = total - tens;
  46. fives = dollar/5;
  47. total = total - fives;
  48. ones = dollar/1;
  49. total = total - ones;
  50.  
  51.  
  52.  
  53.  
  54. return;
  55. }
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 338
Reputation: cikara21 is an unknown quantity at this point 
Solved Threads: 66
cikara21's Avatar
cikara21 cikara21 is offline Offline
Posting Whiz

Re: Change fucntion homework help.

 
0
  #2
Dec 10th, 2008
This for free..Enjoy..
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. void change(float,float &,float &,float &,float &,float &,float &);
  5.  
  6. int main()
  7. {
  8. float dollar;
  9. float hundreds,fifties,twenties,tens,fives,ones;
  10. cout << "Enter dollar amount :\n";
  11. cin >> dollar;
  12. change(dollar,hundreds,fifties,twenties,tens,fives,ones);
  13. cout << "Least change of" << dollar << "is...";
  14.  
  15. cout << "Hundreds :" << hundreds;
  16. cout << "Fifties :" << fifties;
  17. cout << "Twenties :" << twenties;
  18. cout << "Tens :" << tens;
  19. cout << "Fives :" << fives;
  20. cout << "Ones :" << ones;
  21.  
  22.  
  23.  
  24.  
  25.  
  26.  
  27.  
  28.  
  29. }
  30.  
  31. void change(float dollar,float &hundreds, float &fifties, float &twenties, float &tens, float &fives, float &ones)
  32. {
  33. float total=0.0;
  34.  
  35.  
  36. while(total >=0.0)
  37. hundreds = dollar/100.0;
  38. total = total - hundreds;
  39. fifties = dollar/50.0;
  40. total = total - fifties;
  41. twenties = dollar/20.0;
  42. total = total - twenties;
  43. tens = dollar/10.0;
  44. total = total - tens;
  45. fives = dollar/5.0;
  46. total = total - fives;
  47. ones = dollar/1.0;
  48. total = total - ones;
  49.  
  50.  
  51.  
  52.  
  53. return;
  54. }
Last edited by cikara21; Dec 10th, 2008 at 11:07 am.
.:-cikara21-:.
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 8
Reputation: brandn. is an unknown quantity at this point 
Solved Threads: 0
brandn. brandn. is offline Offline
Newbie Poster

Re: Change fucntion homework help.

 
0
  #3
Dec 10th, 2008
Originally Posted by cikara21 View Post
This for free..Enjoy..
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. void change(float,float &,float &,float &,float &,float &,float &);
  5.  
  6. int main()
  7. {
  8. float dollar;
  9. float hundreds,fifties,twenties,tens,fives,ones;
  10. cout << "Enter dollar amount :\n";
  11. cin >> dollar;
  12. change(dollar,hundreds,fifties,twenties,tens,fives,ones);
  13. cout << "Least change of" << dollar << "is...";
  14.  
  15. cout << "Hundreds :" << hundreds;
  16. cout << "Fifties :" << fifties;
  17. cout << "Twenties :" << twenties;
  18. cout << "Tens :" << tens;
  19. cout << "Fives :" << fives;
  20. cout << "Ones :" << ones;
  21.  
  22.  
  23.  
  24.  
  25.  
  26.  
  27.  
  28.  
  29. }
  30.  
  31. void change(float dollar,float &hundreds, float &fifties, float &twenties, float &tens, float &fives, float &ones)
  32. {
  33. float total=0.0;
  34.  
  35.  
  36. while(total >=0.0)
  37. hundreds = dollar/100.0;
  38. total = total - hundreds;
  39. fifties = dollar/50.0;
  40. total = total - fifties;
  41. twenties = dollar/20.0;
  42. total = total - twenties;
  43. tens = dollar/10.0;
  44. total = total - tens;
  45. fives = dollar/5.0;
  46. total = total - fives;
  47. ones = dollar/1.0;
  48. total = total - ones;
  49.  
  50.  
  51.  
  52.  
  53. return;
  54. }
[/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 ....
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 338
Reputation: cikara21 is an unknown quantity at this point 
Solved Threads: 66
cikara21's Avatar
cikara21 cikara21 is offline Offline
Posting Whiz

Re: Change fucntion homework help.

 
0
  #4
Dec 10th, 2008
How about this
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. void change(float,float &,float &,float &,float &,float &,float &);
  5.  
  6. int main()
  7. {
  8. float dollar;
  9. float hundreds,fifties,twenties,tens,fives,ones;
  10. cout << "Enter dollar amount :\n";
  11. cin >> dollar;
  12. change(dollar,hundreds,fifties,twenties,tens,fives,ones);
  13. cout << "Least change of" << dollar << "is...";
  14.  
  15. cout << "Hundreds :" << hundreds;
  16. cout << "Fifties :" << fifties;
  17. cout << "Twenties :" << twenties;
  18. cout << "Tens :" << tens;
  19. cout << "Fives :" << fives;
  20. cout << "Ones :" << ones;
  21.  
  22.  
  23.  
  24.  
  25.  
  26.  
  27.  
  28.  
  29. }
  30.  
  31. void change(float dollar,float &hundreds, float &fifties, float &twenties, float &tens, float &fives, float &ones)
  32. {
  33. float total=0.0;
  34.  
  35.  
  36. while(total >=0.0)
  37. {
  38. hundreds = dollar/100.0;
  39. total = total - hundreds;
  40. fifties = dollar/50.0;
  41. total = total - fifties;
  42. twenties = dollar/20.0;
  43. total = total - twenties;
  44. tens = dollar/10.0;
  45. total = total - tens;
  46. fives = dollar/5.0;
  47. total = total - fives;
  48. ones = dollar/1.0;
  49. total = total - ones;
  50.  
  51. }
  52.  
  53.  
  54.  
  55. return;
  56. }
.:-cikara21-:.
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 8
Reputation: brandn. is an unknown quantity at this point 
Solved Threads: 0
brandn. brandn. is offline Offline
Newbie Poster

Re: Change fucntion homework help.

 
0
  #5
Dec 10th, 2008
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.
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 8
Reputation: brandn. is an unknown quantity at this point 
Solved Threads: 0
brandn. brandn. is offline Offline
Newbie Poster

Re: Change fucntion homework help.

 
0
  #6
Dec 10th, 2008
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...
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 8
Reputation: brandn. is an unknown quantity at this point 
Solved Threads: 0
brandn. brandn. is offline Offline
Newbie Poster

Re: Change fucntion homework help.

 
0
  #7
Dec 10th, 2008
  1. while(total >=0.0)
  2. {
  3. hundreds = dollar/100.0;
  4. total = total - (hundreds * 100.0);
  5. fifties = dollar/50.0;
  6. total = total - (fifties * 50.0);
  7. twenties = dollar/20.0;
  8. total = total - (twenties * 20.0);
  9. tens = dollar/10.0;
  10. total = total - (tens * 10.0);
  11. fives = dollar/5.0;
  12. total = total - (fives * 5.0);
  13. ones = dollar/1.0;
  14. 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
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 338
Reputation: cikara21 is an unknown quantity at this point 
Solved Threads: 66
cikara21's Avatar
cikara21 cikara21 is offline Offline
Posting Whiz

Re: Change fucntion homework help.

 
0
  #8
Dec 10th, 2008
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. void change(float,int &,int &,int &,int &,int &,int &);
  5.  
  6. int main()
  7. {
  8. float dollar;
  9. int hundreds,fifties,twenties,tens,fives,ones;
  10. cout << "Enter dollar amount :\n";
  11. cin >> dollar;
  12. change(dollar,hundreds,fifties,twenties,tens,fives,ones);
  13. cout << "Least change of" << dollar << "is...";
  14.  
  15. cout << "Hundreds :" << hundreds;
  16. cout << "Fifties :" << fifties;
  17. cout << "Twenties :" << twenties;
  18. cout << "Tens :" << tens;
  19. cout << "Fives :" << fives;
  20. cout << "Ones :" << ones;
  21.  
  22.  
  23.  
  24.  
  25.  
  26.  
  27.  
  28.  
  29. }
  30.  
  31. void change(float dollar,int &hundreds, int &fifties, int &twenties, int &tens, int &fives, int &ones)
  32. {
  33. hundreds = dollar/100;
  34. fifties = dollar/50;
  35.  
  36. twenties = dollar/20;
  37. tens = dollar/10;
  38.  
  39. fives = dollar/5;
  40.  
  41. ones = dollar/1;
  42.  
  43.  
  44.  
  45. return;
  46. }
Last edited by cikara21; Dec 10th, 2008 at 12:36 pm.
.:-cikara21-:.
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 8
Reputation: brandn. is an unknown quantity at this point 
Solved Threads: 0
brandn. brandn. is offline Offline
Newbie Poster

Re: Change fucntion homework help.

 
0
  #9
Dec 10th, 2008
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.
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 338
Reputation: cikara21 is an unknown quantity at this point 
Solved Threads: 66
cikara21's Avatar
cikara21 cikara21 is offline Offline
Posting Whiz

Re: Change fucntion homework help.

 
0
  #10
Dec 10th, 2008
I'm not sure..
  1. void change(float dollar,int &hundreds, int &fifties, int &twenties, int &tens, int &fives, int &ones)
  2. {
  3. int total=0;
  4. hundreds=dollar/100;
  5. total=((int)dollar
  6. %100);
  7. fifties=total/50;
  8.  
  9. total=((int)dollar%50);
  10. twenties=total/20;
  11.  
  12. total=((int)dollar%20);
  13. tens=total/10;
  14.  
  15. total=((int)dollar%10);
  16. fives=total/5;
  17.  
  18. total=((int)dollar%5);
  19. ones=total/1;
  20.  
  21. return;
  22. }
.:-cikara21-:.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum


Views: 825 | Replies: 12
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC