Professional Documents
Culture Documents
Review Questions
1. a after
2. a do while
3. d both b and c
4. a 0, 1, 2, 3, 4
5. b 16, 12
6. b 8
7. d 3, 5
8. a ***
***
9. d 30
Exercises – Computer
9. The answer to this TRY THIS Exercise is located at the end of Chapter 8 in the book. The code is entered
in the TryThis9.cpp file, which is contained in either the Cpp8\Chap08\TryThis9 Project-IM folder
(Microsoft) or the Cpp8\Chap08 folder (non-Microsoft).
Algorithm:
1. enter the beginning salary
2. repeat while (the beginning salary > 0)
assign the beginning salary to the new salary
Processing
new salary
double newSalary = 0.0;
Output
double raise = 0.0;
raise (for 3 years at different raise rates)
repeat for (raise rate from 3% for (double rate = .03; rate < .07;
rate += .01)
to 6% in increments of 1%)
{
cout << "Raise rate: "
display the current raise rate << rate * 100 << "%" << endl;
repeat for (year from 1 to 3) for (int year = 1; year < 4; year +=
1)
{
display the current year cout << "Year " << year << ":";
Algorithm:
1. repeat for (dealership from 1 to 3)
enter the sales
Processing
dealership (counter: 1 to 3)
this variable is created and initialized in the for clause
Output
total sales int totalSales = 0;
repeat while (the sales are greater than 0) while (dealerSales > 0)
{
add the sales to the total sales totalSales += dealerSales;
cout << "Next sales amount
enter the sales
for dealership " << dealer
<< " (0 or a negative
number to end): ";
cin >> dealerSales;
end repeat }//end while
cout << endl;
end repeat }//end for
2. display total sales cout << "Total sales: $" << totalSales
<< endl;
20. See the Advanced20.cpp file, which is contained in either the Cpp8\Chap08\Advanced20 Project-IM folder
(Microsoft) or the Cpp8\Chap08 folder (non-Microsoft).
21. See the Advanced21.cpp file, which is contained in either the Cpp8\Chap08\Advanced21 Project-IM folder
(Microsoft) or the Cpp8\Chap08 folder (non-Microsoft).
Solution Manual for An Introduction to Programming with C++, 8th Edition
22. See the SwatTheBugs22.cpp file, which is contained in either the Cpp8\Chap08\SwatTheBugs22 Project-
IM folder (Microsoft) or the Cpp8\Chap08 folder (non-Microsoft). To debug the program, change the outer
loop’s update argument to outer += 1. Also enclose the number += 2; and cout << number
<< " "; statements in a set of braces.