| | |
Assistance with change program
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Oct 2005
Posts: 62
Reputation:
Solved Threads: 0
i have this simple program im writing to help my dads business.
thoguh it doesnt seem to be working, this is what i have currently
i dont know if ive got the right idea or anything
this is sorta what im trying to write, a C++ function, named change(), that has a floating-point parameter and 5 integer reference parameters named onedollars, fiftycents, twentycents, tencents and fivecents. The function is to consider the floating-point passed value as a dollar amount and convert the value into an equivalent number of dollar coins, fifty, twenty, ten and five cents coins. Using the references, the function should directly alter the respective arguments in the calling function.
For example, calling the function with the following arguments: change(78.85, onedollars, fiftycents, twentycents, tencents, fivecents); will assign the following values to the appropriate variables:
onedollars = 78
fiftycents = 1
twentycents = 1
tencents = 1
fivecents = 1
any help wuld b awsome
thoguh it doesnt seem to be working, this is what i have currently
c++ Syntax (Toggle Plain Text)
#include<iostream> using namespace std; int change(double money,int onedollar,int fiftycent,int twentycent,int tencent,int fivecent); int main() { int money, onedollar, fiftycent, twentycent, tencent, fivecent; cout << "Enter amount: "; cin >> money; change(money, onedollar, fiftycent, twentycent, tencent, fivecent); cout << "One Dollar: " << onedollar << endl; cout << "Fifty Cent: " << fiftycent << endl; cout << "Twenty Cent: " << twentycent << endl; cout << "Ten Cent: " << tencent << endl; cout << "Five Cent: " << fivecent << endl; return 0; } int change(float money, int onedollar, int fiftycent, int twentycent, int tencent, int fivecent) { float temp; temp = money; temp *= 100; onedollar = temp/100; temp = temp%100; fiftycent = temp/50; temp = temp%50; twentycent = temp/20; temp = temp%20; tencent = temp/10; temp = temp%10; fivecent = temp/5; return 0; }
i dont know if ive got the right idea or anything
this is sorta what im trying to write, a C++ function, named change(), that has a floating-point parameter and 5 integer reference parameters named onedollars, fiftycents, twentycents, tencents and fivecents. The function is to consider the floating-point passed value as a dollar amount and convert the value into an equivalent number of dollar coins, fifty, twenty, ten and five cents coins. Using the references, the function should directly alter the respective arguments in the calling function.
For example, calling the function with the following arguments: change(78.85, onedollars, fiftycents, twentycents, tencents, fivecents); will assign the following values to the appropriate variables:
onedollars = 78
fiftycents = 1
twentycents = 1
tencents = 1
fivecents = 1
any help wuld b awsome
•
•
Join Date: Dec 2006
Posts: 1,089
Reputation:
Solved Threads: 164
yes. and if you want the function to have output parameters, pass them by reference, not value.
also passing the amount in cents (as an integer) rather than a float would help avoid floating point round off errors.
also passing the amount in cents (as an integer) rather than a float would help avoid floating point round off errors.
Last edited by vijayan121; Apr 22nd, 2007 at 1:04 pm.
•
•
Join Date: Oct 2006
Posts: 3
Reputation:
Solved Threads: 0
You should have a function called change so that you can intiate it once and call it whenever you need it!
•
•
•
•
i have this simple program im writing to help my dads business.
thoguh it doesnt seem to be working, this is what i have currently
c++ Syntax (Toggle Plain Text)
#include<iostream> using namespace std; int change(double money,int onedollar,int fiftycent,int twentycent,int tencent,int fivecent); int main() { int money, onedollar, fiftycent, twentycent, tencent, fivecent; cout << "Enter amount: "; cin >> money; change(money, onedollar, fiftycent, twentycent, tencent, fivecent); cout << "One Dollar: " << onedollar << endl; cout << "Fifty Cent: " << fiftycent << endl; cout << "Twenty Cent: " << twentycent << endl; cout << "Ten Cent: " << tencent << endl; cout << "Five Cent: " << fivecent << endl; return 0; } int change(float money, int onedollar, int fiftycent, int twentycent, int tencent, int fivecent) { float temp; temp = money; temp *= 100; onedollar = temp/100; temp = temp%100; fiftycent = temp/50; temp = temp%50; twentycent = temp/20; temp = temp%20; tencent = temp/10; temp = temp%10; fivecent = temp/5; return 0; }
i dont know if ive got the right idea or anything
this is sorta what im trying to write, a C++ function, named change(), that has a floating-point parameter and 5 integer reference parameters named onedollars, fiftycents, twentycents, tencents and fivecents. The function is to consider the floating-point passed value as a dollar amount and convert the value into an equivalent number of dollar coins, fifty, twenty, ten and five cents coins. Using the references, the function should directly alter the respective arguments in the calling function.
For example, calling the function with the following arguments: change(78.85, onedollars, fiftycents, twentycents, tencents, fivecents); will assign the following values to the appropriate variables:
onedollars = 78
fiftycents = 1
twentycents = 1
tencents = 1
fivecents = 1
any help wuld b awsome
![]() |
Similar Threads
- Here Is Another Way I Wrote This Program Which Is Due (Python)
- Digital Time Program (C)
- cannot remove the program (Windows NT / 2000 / XP)
- Multi-user program issues (VB.NET)
- Memory Resident Program (Assembly)
Other Threads in the C++ Forum
- Previous Thread: how do i saw every lines in my database w/c i have entered.?
- Next Thread: Reading a text file
| Thread Tools | Search this Thread |
api array arrays based binary bitmap c++ c/c++ calculator char char* class classes code coding compile console conversion convert count data database delete deploy developer dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game generator getline givemetehcodez google graph gui homeworkhelp iamthwee ifstream input int java lib linkedlist linker list loop looping loops map math matrix memory multiple news node number numbertoword output pointer problem program programming project python random read recursion recursive reference rpg sorting string strings temperature template test text text-file tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






