/* Copyright: 2000, All rights reserved. Program: DoubleMoney Version: 1.0 Created/Revised: 4/2/00 File: doublemoney.cpp Programmer: C. S. Tritt, Ph.D. Course: CS-150 Assignment: Example Compiler: Microsoft Visual C++ 6.0 Target: Win32 Description: This program calculates the time to double an investment given some specific conditions including a monthly fee. It is based on the example on page 237 in Horstmann's CCC 2nd ed. Revisions: There have been no major revisions of this program. Constants and Variables: See code for constant and variable descriptions. */ // Included files. #include // These macros mimic the ANSI C++ logical operations. #define and && #define or || #define not ! using namespace std; int main() { const double MPY = 12.; // Months per year. const double PRCNT = 100.; // Percentage conversion. // Get user input. double apr; // Annual percentage rate. cout << "Enter annual percentage rate: "; cin >> apr; double rate = apr / MPY / PRCNT; // Convert APR to monthly rate. double ib; // Initial balance. cout << "Enter initial balance: "; cin >> ib; double fb = 2.0*ib; // Final balance should be twice the initial balance. double balance = ib; // The balance starts as the initial balance. double fee; // Monthly fee. cout << "Enter monthly fee: "; cin >> fee; int month = 0; // Find time to double or loss investment. while (balance < fb and balance > 0) // alternate condition (not (balance >= fb or balance <=0)) { month = month + 1; // Increament month. Alternative month = month + 1 balance = balance * (1. + rate) - fee; cout << balance << "\n"; } // Tell the user what happened. if (balance >= fb) { cout << "You will double your money in " << month << " month(s).\n"; } else { cout << "Your money will be gone after " << month << " month(s).\n"; } // Everything worked. return 0; }