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

``````#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

## All 5 Replies

what you need is integer division. in your program, temp is a float. float(123)/100 will give you 1.23, not 1. and a standards-compliant compiler would give you a compile-time error if you try float(123)%100

so something like

``````int temp

temp = money * 100``````

?

so something like

``````int temp

temp = money * 100``````

?

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.

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

``````#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

i have this simple program im writing to help my dads business.

Yeah, right. Look, we don't mind helping people with their homework assignments. So you don't have to lie about it in a lame attempt to get homework help.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.