I am working on a homework assignment and have most of the program working, but when I try to compile it keeps telling me to initialize the coin variables in each class. However, they are supposed to be added then removed so I don't want to set them back to zero. Any help would be appreciated!
Rewrite the Purse program given in Page 35 with functions to perform insert and remove operations. The function insert (int p, int n, int d, int q) will initialize pennies, nickels, dimes and quarters. The function dollars() will return the dollars. The function remove (int p, int n, int d, int q) will subtract pennies, nickels, dimes and quarters. The function display() returns a new String to print the content of the purse with remaining pennies, nickels, dimes and quarters.
Code:
usingnamespace std;
int insert_money (int *p, int *n, int *d, int *q);
int remove_money (int *p, int *n, int *d, int *q);
int dollars();
int main()
{
int pennies, nickels, dimes, quarters;
int p, n, d, q;
cout << "\nTime to insert some money";
cout << "\nNumber of pennies to insert: ";
cin >> p;
cout << "\nNumber of nickels to insert: ";
cin >> n;
cout << "\nNumber of dimes to insert: ";
cin >> n;
cout << "\nNumber of quarters to insert: ";
cin >> q;
cout << quarters << "quarters " << dimes << "dimes" << nickels << "nickels" << pennies << "pennies" << insert_money(int *p, int *n, int *d, int *q;
cout << "\nTime to insert some money";
cout << "\nNumber of pennies to insert: ";
cin >> p;
cout << "\nNumber of nickels to insert: ";
cin >> n;
cout << "\nNumber of dimes to insert: ";
cin >> n;
cout << "\nNumber of quarters to insert: ";
cin >> q;
cout << quarters << "quarters " << dimes << "dimes" << nickels << "nickels" << pennies << "pennies" << insert_money(int *p, int *n, int *d, int *q;
}
int insert_money(int *p, int *n, int *d, int *q)
{
int pennies = 0, nickels = 0, dimes = 0, quarters = 0;
pennies += *p;
nickels += *n;
dimes += *d;
quarters += *q;
}
int remove_money(int *p, int *n, int *d, int *q)
{
int pennies, nickels, dimes, quarters;
pennies -= *p;
nickels -= *n;
dimes -= *d;
quarters -= *q;
}
int dollars(int pennies, int nickels, int dimes, int quarters, double total)
{
total = pennies + 5*nickels + 10*dimes + 25*quarters;
total = (float)total/100.0;
return total;
}