Question

In: Computer Science

I wrote a c++ program that is suppose to calculate the interest on a CD account...

I wrote a c++ program that is suppose to calculate the interest on a CD account but, I cant get the formula to calculate it correctly. 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;

account accountinfo;

info(accountinfo);

calc1 = (accountinfo.interest_rate / 100) + 1;

calc2 = pow(calc1, accountinfo.term);

accountinfo.balance = accountinfo.balance * calc2;

cout << " " << endl

<< " The balance of your CD account after it has matured in " << accountinfo.term << endl

<< " at a interest rate of " << accountinfo.interest_rate << " will be " << accountinfo.balance << 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. " << endl

<< " " << endl;

cin >> accountinfo.term;

}

Solutions

Expert Solution

The formula for calculating the CD interest is as follows:

The code what you have written is correct only.

For example:

Let's say

balance = 1000

interest rate = 2

term = 10

Then we have the interest = 1000 * ( 2/100 + 1 )10

= 1000 * (0.02 + 1 )10

= 1000 *(1.02)10

= 1000 * 1.2189944

=1218.9944

YOU DON't NEED TO CHANGE ANY CODE:

SAME 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;

account accountinfo;

info(accountinfo);

calc1 = (accountinfo.interest_rate / 100) + 1;

calc2 = pow(calc1, accountinfo.term);

accountinfo.balance = accountinfo.balance * calc2;

cout << " " << endl

<< " The balance of your CD account after it has matured in " << accountinfo.term << endl

<< " at a interest rate of " << accountinfo.interest_rate << " will be " << accountinfo.balance << 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. " << endl

<< " " << endl;

cin >> accountinfo.term;

}

================================


Related Solutions

*********C++ Program************ Enhance the Account class to compute the interest on the current balance. An account...
*********C++ Program************ Enhance the Account class to compute the interest on the current balance. An account has initial balance of $10,000.00, and 6% percent annual interest is compounded monthly until the investment is double. Write a main function to determine the number of months to double the initial investment. Create function name "double investment" for this project. Create a menu to allow the user to enter the initial investment and the annual interest rate. Please create a header file(bank.h) and...
When I wrote this code in the Eclipse program, I did not see a output .....
When I wrote this code in the Eclipse program, I did not see a output .. Why? _______ public class AClass { private int u ; private int v ; public void print(){ } public void set ( int x , int y ) { } public AClass { } public AClass ( int x , int y ) { } } class BClass extends AClass { private int w ; public void print() { System.out.println (" u + v...
I wrote this program to check a string is palindrome or not. but in both cases,...
I wrote this program to check a string is palindrome or not. but in both cases, it gives me palindrome. could someone help me with this program? it has an error I couldn't find. when I run the code and give a string, in both cases it gives me palindrome. for example if I give Pop it says it is a palindrome but if I give Salima, it also says palindrome. #include<string> #include <iostream> using namespace std; class PString:public string...
in python, sorry i thought i wrote it Write an interactive program that repeatedly asks the...
in python, sorry i thought i wrote it Write an interactive program that repeatedly asks the user to input a number until”Enter” is hit. Your program should create a file named “numbers.txt” where all the numbersare written one below the other, and the last line should display the sum of all the input, afterthe string “The sum of your numbers is ”.For example, if the user inputs 3, 5, 7, 10, -3, 5.2, then the file “numbers.txt” should contain: 3...
Java Using NetBean Calculate the interest for a bank account. Your program should use Scanner to...
Java Using NetBean Calculate the interest for a bank account. Your program should use Scanner to collect account balance and interest rate (input 2.5 for 2.5%), and then output the interest should be paid. interest = balance * interest_rate;
I. Design the C++ code for a program which will use the Pythagorean Theroem to calculate...
I. Design the C++ code for a program which will use the Pythagorean Theroem to calculate and display the length of a right triangle hypotenuse,c, given the lengths of its adjacent sides: a and b.. (hint: a^2 + b^2 = c^2) II. Design the C++ code for a program which will calculate and display the roots of a quadratic equation of the form ax^2 + bx + c = 0, given its coefficients, a, b, and c.
Calculate the future value of a $4,000 CD earning 5.2% interest for 8 years under the...
Calculate the future value of a $4,000 CD earning 5.2% interest for 8 years under the following scenarios (use a calculator for the algebraic formula answer, check using the =FV function). (in Excel use =FV(i,n,0,(PV),0). Make PV negative because it is a cash out-flow. (Use the EXP function for the continuous compounding problem.) Show what Algebraic Formula you use. Submit a screenshot of this sheet filled out with the algebraic calculations, and submit your excel spreadsheet with an identifiable name...
Calculate the future value of a $4,000 CD earning 5.2% interest for 8 years under the...
Calculate the future value of a $4,000 CD earning 5.2% interest for 8 years under the following scenarios (use a calculator for the algebraic formula answer, check using the =FV function). (in Excel use =FV(i,n,0,(PV),0). Make PV negative because it is a cash out-flow.   (Use the EXP function for the continuous compounding problem.) Show what Algebraic Formula you use. Submit a screenshot of this sheet filled out with the algebraic calculations, and submit your excel spreadsheet with an identifiable name...
I need program to calculate the number of seconds since midnight. For example, suppose the time...
I need program to calculate the number of seconds since midnight. For example, suppose the time is 1:02:05 AM. Since there are 3600 seconds per hour and 60 seconds per minutes, it has been 3725 seconds since midnight (3600 * 1 + 2 * 60 + 5 = 3725). The program asks the user to enter 4 pieces of information: hour, minute, second, and AM/PM. The program will calculate and display the number of seconds since midnight. Modify the program...
MUST BE DONE IN C (NOT C++) In this program we will calculate the average of...
MUST BE DONE IN C (NOT C++) In this program we will calculate the average of x students’ grades (grades will be stored in an array). To do so, please follow these guidelines: - Your program should ask the user for the number of students that are in the class. This number should help you declare your array. - Use the function seen in class to scan the grades of the array. In other words, we will populate the array...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT