C++ Fix this code so that it displays in the format like the image shown where the principal and rate should have a fixed precision of 2 for each of the five percentages 5%,6%,7%,8%,9%,10%. The amount of the deposit should not have the fixed precision and should remain in the decimal format. #include #include #include using namespace std; int main() { double principal{ 1000 }; double rate{ 0.05 }; for (rate; rate <= 0.10; rate += 0.01) { cout << "" << endl; cout << "Initial principal: " << principal << endl; cout << "Interest Rate: " << rate * 100 << "%" << endl; cout << setw(4) << "Year" << setw(20) << "Amount on deposit" << endl; for (unsigned int year{ 1 }; year <= 10; year++) { double amount = principal * pow(1.0 + rate, year); cout << setw(4) << year << setw(20) << amount << endl; } } }
C++
Fix this code so that it displays in the format like the image shown where the principal and rate should have a fixed precision of 2 for each of the five percentages 5%,6%,7%,8%,9%,10%. The amount of the deposit should not have the fixed precision and should remain in the decimal format.
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
int main()
{
double principal{ 1000 };
double rate{ 0.05 };
for (rate; rate <= 0.10; rate += 0.01) {
cout << "" << endl;
cout << "Initial principal: " << principal << endl;
cout << "Interest Rate: " << rate * 100 << "%" << endl;
cout << setw(4) << "Year" << setw(20) << "Amount on deposit" << endl;
for (unsigned int year{ 1 }; year <= 10; year++) {
double amount = principal * pow(1.0 + rate, year);
cout << setw(4) << year << setw(20) << amount << endl;
}
}
}
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 2 images