12 In this exercise you will modify the car depreciation pro
12. In this exercise, you will modify the car depreciation program from Figure 8-12. Follow the instructions for starting C++ and viewing the ModifyThis12.cpp file, which is contained in either the Cpp8 Chap08 ModifyThis12 Project folder or the Cpp8 Chap08 folder. (Depending on your C++ development tool, you may need to open the project/ solution file first.) Replace the nested for statement with a while statement. Test the program appropriately.
Solution
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
double originalValue = 0.0;
double depreciation = 0.0;
double currentValue = 0.0;
cout<<\"Enter originalValue: \";
cin>>originalValue;
cout<<endl<<fixed<<setprecision(0);
double rate = 0.15;
while(rate<0.26)
{
cout<<\"Depreciation rate: \"<<rate*100<<\"%\"<<endl;
cout<<\"Value after year: \"<<endl;
currentValue = originalValue;
int year=1;
while(year<6)
{
depreciation = currentValue*rate;
currentValue -= depreciation;
cout<<year<<\" $\"<<currentValue<<endl;
year+=1;
}
rate+=0.05;
}
}
