UMBC CMSC 202
UMBC CMSC 202 CSEE | 202 | current 202

This code is a modified version of the textbook example 1.4 found on page 20.

//--------------------------------------------------- // File : 01-04.cpp // Author : D. Frey // Date : 13 June 2003 // UMBC Email: frey@cs.umbc.edu // Project : none // Section : 0123 // Description: // This file is a modified version of the textbook // example 01-04. It's purpose is to provide a basic // example of C++ coding. //--------------------------------------------------- #include <iostream> using namespace std; int main( ) { const double RATE = 6.9; // interest percentage double deposit; cout << "Enter the amount of your deposit $"; cin >> deposit; // "magic formula" for decimal output cout.setf( ios::fixed ); cout.setf( ios::showpoint ); cout.precision( 2 ); // calculate and output balance with interest double newBalance; newBalance = deposit + deposit * ( RATE / 100 ); cout << "In one year, that deposit will grow to\n" << "$" << newBalance << " -- an amount worth waiting for.\n"; return 0; }

Sample Run

linuxserver1[106] a.out Enter the amount of your deposit $43 In one year, that deposit will grow to $45.97 -- an amount worth waiting for. linuxserver1[107] a.out Enter the amount of your deposit $45.00 In one year, that deposit will grow to $48.10 -- an amount worth waiting for. linuxserver1[108] a.out Enter the amount of your deposit $76.66 In one year, that deposit will grow to $81.95 -- an amount worth waiting for. linuxserver1[111] a.out Enter the amount of your deposit $wer In one year, that deposit will grow to $0.00 -- an amount worth waiting for.


Last Modified: Monday, 28-Aug-2006 10:15:54 EDT