In: Computer Science
Consider the following scenario and design a C++ program using an output stream file: A person invests $1,000 on a savings account yielding 5% interest. Assuming that all the interest is left on deposit, calculate and print the amount of money in the account at the end of each year for 10 years. Use the following formula to determine the amounts: a = p (1 + r)n where p is the original amount invested (i.e., the principal) r is the annual interest rate (e.g., use 0.05 for 5%)f n is the number of years a is the amount on deposit at the end of the nth year. Your program must have an output file to display your results.
#include <iostream> #include <fstream> using namespace std; int main() { ofstream output("output.txt"); double p, r; int n; cout << "Enter principal amount: "; cin >> p; cout << "Enter interest rate: "; cin >> r; cout << "Enter number of years: "; cin >> n; for(int i=0; i<n; i++) { p = p * (1 + r/100.0); output << "Balance at end of year " << (i + 1) << ": "; output << p << endl; } output.close(); }
************************************************** Thanks for your question. We try our best to help you with detailed answers, But in any case, if you need any modification or have a query/issue with respect to above answer, Please ask that in the comment section. We will surely try to address your query ASAP and resolve the issue.
Please consider providing a thumbs up to this question if it helps you. by Doing that, You will help other students, who are facing similar issue.