be done. You should only add one line of code. #include #include #include using namespace std; double colleg
Types of Loop
Loops are the elements of programming in which a part of code is repeated a particular number of times. Loop executes the series of statements many times till the conditional statement becomes false.
Loops
Any task which is repeated more than one time is called a loop. Basically, loops can be divided into three types as while, do-while and for loop. There are so many programming languages like C, C++, JAVA, PYTHON, and many more where looping statements can be used for repetitive execution.
While Loop
Loop is a feature in the programming language. It helps us to execute a set of instructions regularly. The block of code executes until some conditions provided within that Loop are true.
The following code does not work. What needs to be fixed? Retype the code and clearly label what needs to be done. You should only add one line of code.
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
double collegeFund(double payment, double interest, double years);
void calculateAndPrint(double payment, double interest, double years);
int main()
{
double futureValue;
double PMT;
double i;
double n = 18;
double annualIncome;
const double COLLEGE_TUITION = 10250 * 4; //Cost per year to attend Texas A&M University. Whoop!
cout << fixed << showpoint << setprecision(2);
cout << "Enter the amount you plan to invest each year: ";
cin >> PMT;
cout << endl;
cout << "Enter the estimated interest rate in decimal format: ";
cin >> i;
cout << endl;
futureValue = collegeFund(PMT, i, n);
cout << "If you invest $" << PMT << " for " << n << " years "
<< "with an interest rate of " << i * 100 << "%" << " then you will have $"
<< futureValue << " for your children's future college fund. \n" << endl;
if (futureValue >= COLLEGE_TUITION)
cout << "Your child will have the necessary funds to attend any in-state college." << endl;
else
{
cout << "Please enter your annual income: ";
cin >> annualIncome;
cout << endl;
if (annualIncome > 50000)
cout << "Your child will have to work and/or borrow money for college.\n";
else
cout << "Hopfully the difference will be made up by Pell grants. Try to save more.\n\n";
}
calculateAndPrint(PMT, i, n);
system("pause");
return 0;
}
//Function to return yearly investment with accumulated interests in 18 years.
double collegeFund(double payment, double interest, double years)
{
return payment * (pow((1 + interest), years) - 1) / interest;
}
//Function to calculate and print out yearly investment with accumulated interest per year for 18 years.
void calculateAndPrint(double payment, double interest, double years)
{
cout << "As an incentive to save early, please note the accumulated principal plus interest each year.\n"
<< endl;
for (int i = 0; i < years ; i++)
{
double FV;
FV = payment * ((pow((1 + interest), (i+1)) - 1) / interest);
interestPlusPrincipal[i] = FV;
cout << "Year " << i + 1 << " $" << interestPlusPrincipal[i] << endl;
}
}
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 1 images