1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190
|
#include <iostream>
#include <stdlib.h>
#include <cmath>
using namespace std;
double simple_interest (double principal, double rate, double time);
double compound_interest (double principal, double rate, double time);
double compound_interest_ear (double principal, double rate, double time, double period);
int main ()
{
double amount, principal, rate, time, interest, R;
int choice;
double SI, CI, EAR, Amount, period;
amount = principal = rate = time = interest = 0.0;
while (choice! = -99)
{
cout << "\n\n\n\n\n";
cout << "\t\t\tEnter Principal amount:"; cin >> principal;
cout << "\t\t\tEnter Rate (In percentage):"; cin >> R;
rate = R/100;
cout << "\t\t\tEnter Time (In Years):"; cin >> time;
cout << "\t\t\t" << principal << endl;
cout << "\t\t\t" << rate << endl;
cout << "\t\t\t" << time << endl;
cout << "\t\t\t************ MENU ********************" << endl;
cout << "\t\t\t1: Simple Interest" << endl;
cout << "\t\t\t2: Compound Interest" << endl;
cout << "\t\t\t3: Effective Annual Rate (Compound Interest)" << endl;
cout << "\t\t\t****************************************" << endl;
cout << "\t\t\tEnter You Choice:"; cin >> choice;
if(choice == 3)
{
cout << "\t\t\tNo of Period in a Year:";
cin >> period;
}
switch(choice)
{
case 1:
SI = simple_interest (principal, rate, time);
Amount = principal + SI;
cout << "\n\n\n";
cout << "\t\t\tSimple Interest =" << " "<< SI << endl;
cout << "\t\t\tTotal Amount =" << " " << Amount<< endl;
break;
case 2:
Amount = compound_interest(principal, rate, time);
CI = Amount - principal;
cout << "\n\n\n";
cout << "\t\t\tCompound Interest with Principal =" << " "
<<
Amount << endl;
cout << "\t\t\tTotal Compound Interest ="<< " " <<
CI << endl;
break;
case 3:
Amount = compound_interest_ear(principal, rate, time, period);
CI = Amount - principal;
EAR = pow((1 + (rate/period)),period)-1;
cout << "\n\n\n";
cout << "\t\t\tCompound Interest with Principal =" << " " <<
Amount << endl;
cout << "\t\t\tTotal Compound Interest =" << " " <<
CI << endl;
cout << "\t\t\tEffective Annual Rate =" << " " <<
EAR << endl;
cout << "\t\t\tNomianal Rate =" << " " <<
rate << endl;
break;
default:
cout << "\t\t\tSorry ! Try again";
break;
}
cout << "\n\n\n";
cout << "\t\t\tDo you want to Continue?" << endl;
cout << "\t\t\tEnter -99 to end" << endl;
cout << "\t\t\tOr Enter any other number to Continue:";
cin << choice;
}
system("PAUSE");
return EXIT_SUCCESS;
}
// Simple interest
double simple_interest(double principal, double rate, double time)
{
double SI = principal * rate * time;
double Amount = principal + SI;
return SI;
}
// Compound Interest
double compound_interest(double principal, double rate, double time)
{
double CI;
double Amount;
Amount = principal * pow((1 + rate),time);
return Amount;
}
// Compound Interest with the effective annual rate
double compound_interest_ear(double principal,double rate, double time,double period)
{
double CI, EAR, Amount;
period = period * time;
Amount = principal * pow((1 + (rate/period)),period);
return Amount;
}
|