Follow the instructions for starting your C++ development tool. Depending on the
ID: 3919151 • Letter: F
Question
Follow the instructions for starting your C++ development tool. Depending on the development tool you are using, you may need to create a new project; if so, name the project Lab7-2 Project, and save it in the Cpp8Chap07 folder. Enter the instruc- tions shown in Figure 7-44 in a source file named Lab7-2.cpp. (Do not enter the line numbers.) Save the file in either the project folder or the Cpp8Chap07 folder. Now follow the appropriate instructions for running the Lab7-2.cpp file. Test the program using 125000 as the current sales amount. If necessary, correct any bugs (errors) in the program.
1 //Lab7-2.cpp - Displays the number of years required 2 //for a company's sales to reach at least $150,000 3 //using a 5.5% annual growth rate. Also displays 4 //the sales at that time. 5 //Created/revi sed by on 6 7 #include 8 #include 9 using namespace std; 10 11 int main() 12 { 13 const double GROWTH_RATE = 0.055; 14 double sales = 0.0; 15 double annual Increase = 0.0; 16 int years = 0; 17 18 cout « "Current year's sales: "; 19 cin » sales; 20 while (sales < 150000.0) 21 { 22 annual Increase = sales * GROWTH_RATE; 23 sales += annual Increase ; 24 years += 1; 25 } //end while 26 27 cout « fixed « setprecision(O) ; 28 cout « "Sales " « years « " years from now: $" 29 « sal es « endl ; 30 31 return 0; 32 } //end of main function
Explanation / Answer
//Test the program using 125000 as the current sales amount. If necessary, correct any bugs (errors) in the program.
//Lab7-2.cpp - Displays the number of years required
//for a company's sales to reach at least $150,000
//using a 5.5% annual growth rate. Also displays
//the sales at that time.
//Created/revi sed by on
#include <iostream> //debug comments------ added iostream for standard input and output
#include <iomanip> //debug comments-------- added iomanip for standard input and output for data maniputlation output
using namespace std;
int main()
{
const double GROWTH_RATE = 0.055;
double sales = 0.0;
double annualIncrease = 0.0; //debug comments-------- 'annual Increase' is modifed to 'annualIncrease' . the variable cannot have spaces. It should be valid Identifier
int years = 0;
cout << "Current year's sales: ";
cin >> sales;
while (sales < 150000.0 )
{
annualIncrease = sales * GROWTH_RATE;
sales += annualIncrease ;
years += 1;
} //end while
cout << fixed << setprecision(0) ; //debug comments-------- setprecision(O) -- there list capital letter 'O' is modified to setprecision(0) here we need number '0'
cout << "Sales " << years << " years from now: $"
<< sales << endl ; //debug comments-------- there were extra spaces------ 'sa les' is modified to 'sales'
return 0;
} //end of main function
-----------------output-----------------------
Current year's sales:125000
Sales 4 years from now: $154853