/* Craig Persiko - CS 110A - invest.cpp
Sample program to demonstrate constants and if-statement.
Investment Program
Allows user to enter the amount of an investment.
Investments under $50,000 earn 5% interest, and investments equal to
or above $50,000 earn 6% interest. The dollar amount of interest
earned is output by the program.
*/
#include <iostream>
using namespace std;
int main()
{
const double HIGH_RATE = 0.06, LOW_RATE = 0.05;
// The above values are constants: they cannot be changed
double inv_amount, int_earned;
// Format output to show dollars and cents:
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);
cout << "\nWelcome to Investment World";
cout << "\n\nEnter amount to be invested: $";
cin >> inv_amount;
if(inv_amount < 50000.0)
int_earned = inv_amount * LOW_RATE; // 5% interest
else
int_earned = inv_amount * HIGH_RATE; // 6% interest
// No curly braces are needed above because only one line is
// executed in each case.
cout << "Your investment earns $" << int_earned;
cout << "\n\nEnd of Investment Program\n";
return 0;
}
/* SAMPLE OUTPUT:
Welcome to Investment World
Enter amount to be invested: $100
Your investment earns $5.00
End of Investment Program
-- Trying a different value --
Welcome to Investment World
Enter amount to be invested: $100000
Your investment earns $6000.00
End of Investment Program
*/
syntax highlighted by Code2HTML, v. 0.9