# Storing Data in a Structure

• 11-27-2001
Unregistered
Storing Data in a Structure
Please take a look at my code. I've done "phase 1" - now I'm on "phase 2"

I'm stuck on the last two parts

Here are the instructions

Phase Two::
Enlarge the program to have three MONEY variables. Prompt the user for the various change for two of the MONEY variables; then add the member data items of the two MONEY objects together, using the dot operator to access the member variables and storing the result in the third variable and all three Money variables should be displayed in a dollars and cents format \$ddd.cc and display a count of the number of each type of coin now stored in the third money variable.

Here is what I have for the code. Also If you have any other suggestion -->I'd like to have feedback.

#include <stdio.h>
#include <iostream.h>

struct money
{
int Quarters;
int Dimes;
int Nickles;
int Penny;
};

/***********************************Prototype Declarations************************************** **********/
int caclulate(money getsQuartersDimes, money getsNicklesPennies, int total, money storeFinal);
/************************************************** ************************************************** *****/

int main ()
{

int total=0;
money getsQuarterDimes;
money getsNicklesPennies;
money storeFinal;

cout << "Enter the number of Quarters ";
cin >> getsQuarterDimes.Quarters;
cout << "Enter the number of Dimes ";
cin >> getsQuarterDimes.Dimes;
cout << "Enter the number of Nickles ";
cin >> getsNicklesPennies.Nickles;
cout << "Enter the number of Pennies ";
cin >> getsNicklesPennies.Penny;

total = caclulate(getsQuarterDimes, getsNicklesPennies, total, storeFinal);

cout << "You have " << total << " cents" << endl;

return 0;
}

int caclulate(money getsQuartersDimes, money getsNicklesPennies, int total, money storeFinal)
{
storeFinal.Quarters = getsQuartersDimes.Quarters* 25 ;
storeFinal.Dimes = getsQuartersDimes.Dimes * 10;
storeFinal.Nickles = getsNicklesPennies.Nickles * 5;
storeFinal.Penny = getsNicklesPennies.Penny * 1;

total = storeFinal.Quarters + storeFinal.Dimes + storeFinal.Nickles + storeFinal.Penny ;

}
• 11-28-2001
zen
After you've obtained input for two money variables pass them into a function like -

money add(const money& one, const money& two)
{
money three;
three.Quarters = one.Quarters+two.Quarters;
three.Dimes=one.Dimes+two.Dimes;
//etc

return three;
}

In your main function you'd call it like