cout << "What is your deposit : ";
cin >> p;
cout << "Enter your annual interst rate : ";
cin >>r;
r = r / 100;
cout << "Your deposit : " << p << endl << "Your annual rate : " << r << "%" << endl;
cout << "How many years : ";
cin >> t;
cout << "How many compunds per year : ";
cin >> k;
if (k != 1 and k != 12 and k != 365 and k != 366)
{
cout << "Error, compunds must be daily (365,366) , monthly (12) , annually (1)";
return 1;
}
else
{
e = k * t;
b = 1 + (r / k);
for ( int i = 1; i <= t ; i++)
{
a= p * (pow((1+ r/k), e));
cout << "Amount after "<< i << " year of interest : " << a << endl;
}
}
Since you're doing compound interest, you want to multiply a by pow((1+ r/k), e)) each time. Just set it a = p before the loop, and use a *= pow(b, e) inside. (not 100% don't quote me on this)