In: Computer Science
Cant figure out why my out is wrong for my c++ program.
for example if the initial value is 100, the intrest rate is 10%, and it takes 6 months for maturity the output should be $105 but instead it outputs 101.657 please help.
#include <iostream>
#include <cmath>
using namespace std;
struct account
{
double balance;
double interest_rate;
int term;
};
void info(account& accountinfo);
int main(void)
{
double calc1, calc2, calc3;
account accountinfo;
info(accountinfo);
calc1 = accountinfo.interest_rate / 100;
calc2 = accountinfo.term / 12;
calc3 = (accountinfo.balance * pow (1 + calc1 / 365, 365 / accountinfo.term));
cout << " " << endl
<< " The balance of your CD account after it has matured in " << accountinfo.term << " months " << endl
<< " at a interest rate of " << accountinfo.interest_rate << " percent will be " << calc3 << endl
<< " " << endl;
return 0;
}
void info(account& accountinfo)
{
cout << " " << endl
<< " This program calculates the value of a CD after maturity. " << endl
<< " " << endl
<< " Enter the balance on the account. " << endl;
cin >> accountinfo.balance;
cout << " " << endl
<< " Enter the interest rate for the CD. " << endl
<< " " << endl;
cin >> accountinfo.interest_rate;
cout << " " << endl
<< " Enter the term for the CD to achieve maturity (in months). " << endl
<< " " << endl;
cin >> accountinfo.term;
}
CODE:-
#include <iostream>
#include <cmath>
using namespace std;
struct account
{
double balance;
double interest_rate;
int term;
};
void info(account& accountinfo);
int main(void)
{
double calc1, calc2, calc3;
account accountinfo;
info(accountinfo);
calc1 = accountinfo.interest_rate/100 ;
calc2 =accountinfo.term /12.0;
calc3 = (accountinfo.balance*(1 +(calc1*calc2)));
// modification on the above line A=p(1+rt) here r=calc1
t=calc2
cout << " " << endl << " The balance of your CD
account after it has matured in " << accountinfo.term
<< " months " << endl
<< " at a interest rate of " <<
accountinfo.interest_rate << " percent will be " <<
calc3 << endl << " " << endl;
return 0;
}
void info(account& accountinfo)
{
cout << " " << endl
<< " This program calculates the value of
a CD after maturity. " << endl
<< " " << endl
<< " Enter the balance on the account. "
<< endl;
cin >> accountinfo.balance;
cout << " " << endl
<< " Enter the interest rate for the CD. "
<< endl
<< " " << endl;
cin >> accountinfo.interest_rate;
cout << " " << endl
<< " Enter the term for the CD to achieve
maturity (in months). " << endl
<< " " << endl;
cin >> accountinfo.term;
}