// CD account, demonstrates structure use // Walt Savitch // 03/16/00 #include using std::cin; using std::cout; using std::endl; //Structure for a bank certificate of deposit: struct CDAccount { int balance; int interest_rate; int term; //months until maturity }; // fills up the_account void getData(CDAccount&); int main() { CDAccount account; getData(account); // fill up account // calculate account at maturity double rate_fraction, interest; rate_fraction = account.interest_rate/100.0; interest = account.balance*rate_fraction*(account.term/12.0); account.balance = account.balance + interest; cout << "When your CD matures in " << account.term << " months,\n" << "it will have the balance of $" << account.balance << endl; } // prompts the user about account characteristics // fills up the_account, returns void getData(CDAccount& act) { cout << "Enter account balance: $"; cin >> act.balance; cout << "Enter account interest rate: "; cin >> act.interest_rate; cout << "Enter the number of months until maturity\n" << "(must be 12 or fewer months): "; cin >> act.term; }