Question
1. Change the outer for loop to a posttest loop. Test the program. #include #include using namespace std; int main ( ) { int age
1. Change the outer for loop to a posttest loop. Test the program.
#include
#include
using namespace std;
int main ( )
{
int age = 0;
int currentSalary = 0;
int yearsToRetire = 0;
double newSalary = 0.0;
double total = 0.0;
cout << fixed << setprecision(0);
cout << "Current age in years (1 to 64): ";
cin >> age;
if (age < 1 || age > 64)
cout << "Please enter an age from 1 to 64." << end1;
else
{
cout << "Current salary as a whole number: ";
cin >> currentSalary;
cout << end1;
yearsToRetire = 65 - age;
for (double rate = 0.03; rate < 0.06; rate += 0.01)
{
newSalary = currentSalary; //year 1 salary
total = currentSalary; //year 1 salary
for (int year = 2; year <= yearsToRetire; year += 1)
{
newSalary *= (1 + rate);
total += newSalary;
} // end for
cout << "Total with a" << rate * 100
<< "% annual raise: $" << total << end1;
} // end for
} // end if
return 0;
} // end of main function
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started