ITS250 Week 5 Problem 5 Task A Modify this code and replace

//ITS-250, Week 5 Problem 5

//Task A: Modify this code and replace the while loop with a for loop

//Task B: Modify this code to allow the user the ability to enter the interest rate

#include<iostream>

using namespace std;

int main()

{

   double investment;

   const double INTEREST_RATE = 0.04;

   int years;

   int count = 1;

   cout << \"Enter the amount you have to invest. $ \";

   cin >> investment;

   cout << \"Enter the number of years to invest: \";

   cin >> years;

   while(count <= years)

   {

   cout << \"At the start of year \" << count << \", you have $ \" << investment << endl;

   investment = investment + investment * INTEREST_RATE;

   ++count;

   }

   cout << \"At the end of the investment period, \" << \" you have $\" << investment << endl;

   system(\"PAUSE\");

   return 0;

}

Solution

//Task A: Modify this code and replace the while loop with a for loop
//Task B: Modify this code to allow the user the ability to enter the interest rate

#include<iostream>
using namespace std;
int main()
{
double investment;
int years;
int count = 1;
cout << \"Enter the amount you have to invest. $ \";
cin >> investment;
cout << \"Enter the number of years to invest: \";
cin >> years;
// TASK B:
// To allow the user the ability to enter the interest rate

cout<<\"Enter the interest rate: \";
cin >> INTEREST_RATE;

// TASK A:
// To replace the while loop with a for loop

for(int count=1;count<=years;++count)
{
cout << \"At the start of year \" << count << \", you have $ \" << investment << endl;
investment = investment + investment * INTEREST_RATE;
}
cout << \"At the end of the investment period, \" << \" you have $\" << investment << endl;
system(\"PAUSE\");
return 0;
}

//ITS-250, Week 5 Problem 5 //Task A: Modify this code and replace the while loop with a for loop //Task B: Modify this code to allow the user the ability to en
//ITS-250, Week 5 Problem 5 //Task A: Modify this code and replace the while loop with a for loop //Task B: Modify this code to allow the user the ability to en

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site