1. What must you do if you code an infinite loop in aprogram? - Use a counter...
Question:
1. What must you do if you code an infinite loop in aprogram?
- Use a counter variable to determine when the loop ends
- Use a Boolean expression to determine when the loop ends
- Code just a single statement within the loop
- Stop the application to end the loop
2. Which of the following statements do you use to jump tothe end of a loop from within the loop?
- continue
- break
- end
- repeat
3. How many lines are printed on the console when thefollowing for loop is executed?
for (int i = 2; i < 10; ++i) {
cout << i << endl;
}
- 8
- 9
- 10
- 7
4. How many lines are printed on the console when thefollowing for loops are executed?
for (int i = 1; i < 5; i += 2) {
for (int j = 0; j < i; ++j) {
cout << j < }
}
- 2
- 4
- 5
- 20
5. Code Example 4-2
int main() {
double subtotal = 0.0;
char choice = 'y';
while (choice == 'y') {
cout << "Entersubtotal: ";
cin >>subtotal;
double sales_tax =subtotal * .0875;
double invoice_total =subtotal + sales_tax;
cout << "Subtotal= " << subtotal << ""
<< " Sales tax = " << sales_tax<< ""
<< "Invoice total = " << invoice_total <<"";
cout << "Continue?(y/n): ";
cin >>choice;
cout < }
}
(Refer to Code Example 4-2.) If the userenters “Y” at the Continue prompt, the application will
- repeat the while loop
- display a blank line, then repeat the while loop
- end
Cornerstones of Financial and Managerial Accounting
ISBN: 978-1111879044
2nd edition
Authors: Rich, Jeff Jones, Dan Heitger, Maryanne Mowen, Don Hansen