/* 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()
{
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)
{
if (inv_amount <= 0)
{
int_earned = 0;
cout << "You need to have money to make interest\n";
}
else
{
int_earned = inv_amount * 0.05; // 5% interest
cout << "You're earning 5% interest\n";
}
}
else if(inv_amount < 100000.0)
int_earned = inv_amount * 0.06; // 6% interest
else if(inv_amount < 200000.0)
int_earned = inv_amount * 0.07; // 7% interest
else if(inv_amount < 300000.0)
int_earned = inv_amount * 0.08; // 8% interest
else
int_earned = inv_amount * 0.09; // 9%
cout << "Your investment earns $" << int_earned
<< " interest in one year.";
cout << "Your total in the bank is: $" <<(inv_amount + int_earned);
cout << "\n\nEnd of Investment Program\n";
return 0;
}
/* SAMPLE OUTPUT:
-bash-4.2$ aCC -AA moreInterest.cpp
-bash-4.2$ a.out
Welcome to Investment World
Enter amount to be invested: $100
You're earning 5% interest
Your investment earns $5.00 interest in one year.Your total in the bank is: $105.00
End of Investment Program
-bash-4.2$ a.out
Welcome to Investment World
Enter amount to be invested: $-5
You need to have money to make interest
Your investment earns $0.00 interest in one year.Your total in the bank is: $-5.00
End of Investment Program
-bash-4.2$ a.out
Welcome to Investment World
Enter amount to be invested: $250000
Your investment earns $20000.00 interest in one year.Your total in the bank is: $270000.00
End of Investment Program
-bash-4.2$ a.out
Welcome to Investment World
Enter amount to be invested: $1000000
Your investment earns $90000.00 interest in one year.Your total in the bank is: $1090000.00
End of Investment Program
-bash-4.2$
*/
syntax highlighted by Code2HTML, v. 0.9