| | |
Change fucntion homework help.
Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Dec 2008
Posts: 8
Reputation:
Solved Threads: 0
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.
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.
C++ Syntax (Toggle Plain Text)
#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..
c++ Syntax (Toggle Plain Text)
#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; }
Last edited by cikara21; Dec 10th, 2008 at 11:07 am.
•
•
Join Date: Dec 2008
Posts: 8
Reputation:
Solved Threads: 0
•
•
•
•
This for free..Enjoy..
C++ Syntax (Toggle Plain Text)
#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; }
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 ....
How about this
c++ Syntax (Toggle Plain Text)
#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; }
•
•
Join Date: Dec 2008
Posts: 8
Reputation:
Solved Threads: 0
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.
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.
•
•
Join Date: Dec 2008
Posts: 8
Reputation:
Solved Threads: 0
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...

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...
•
•
Join Date: Dec 2008
Posts: 8
Reputation:
Solved Threads: 0
C++ Syntax (Toggle Plain Text)
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);
c++ Syntax (Toggle Plain Text)
#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; }
Last edited by cikara21; Dec 10th, 2008 at 12:36 pm.
•
•
Join Date: Dec 2008
Posts: 8
Reputation:
Solved Threads: 0
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.
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..
c++ Syntax (Toggle Plain Text)
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; }
![]() |
Similar Threads
Other Threads in the C++ Forum
- Previous Thread: Getting error when calling function from main()
- Next Thread: Dev C++
Views: 825 | Replies: 12
| Thread Tools | Search this Thread |
Tag cloud for C++
6 add api array arrays beginner binary c++ c/c++ calculator char class classes code compile compiler console conversion convert count data delete desktop directshow dll dynamic encryption error file forms fstream function functions game givemetehcodez google graph homeworkhelper iamthwee ifstream input int integer java lazy lib linkedlist linker linux loop looping loops map math matrix memory microsoft newbie news number output parameter pointer problem program programming project proxy python random read recursion recursive reference return sort stream string strings struct studio system template templates test text tree unix url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets





