Question
1. What must you do if you code an infinite loop in aprogram? - Use a counter variable to determine when the loop ends -
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
Step by Step Solution
3.32 Rating (155 Votes )
There are 3 Steps involved in it
Step: 1
Answer and step by step explanation 1 What must you do if you code an infinite loop in a program Use ...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started