Teacher Name:Mr. Rung Date of Lesson: December
Course Name: C++ Lesson Name: Chap 8.2b
Student Name
Password
Objective To complete the workbook exercises.
Primary Focus Please answer the questions below.
Site Links Course Home Page
Additional Resources
Site Links
Question #1
Suppose that for a program that you are writing, you need to validate the users input and repeat the prompt if the user inputs an invalid response. In this case would a while loop or a do while loop be more appropriate?
A: for B: do while C: while D: if then E: None of these
Question #2
Suppose that for a program that you are writing, you need to validate the users input and repeat the prompt if the user inputs an invalid response. In this case would a while loop or a do while loop be more appropriate? Justify your answer.
Question #3
How many times will the loop below iterate? j = 0; while (j < 50) { cout « Hello \n; cout « World \n; }
A: 51 B: 50 C: 0 D: infinitely E: None of these
Question #4
How many times will the loop below iterate? j = 25; while ( j<=100 || j>=25) ( cout <<Temp variable = << j << endl; j = j + 3; }
A: 100 B: 75 C: 0 D: infinitely E: None of these
Question #5
Write a while loop that will print out all the numbers between 3 and 100 that are multiples of three.
Question #6
Identify the errors in the code below. j = 155 while (!done) { if (j <= 25) done = TRUE; j = j 5; };
A: there should be a semicolon at the end of the first line B: It should be j >= 25 C: there shouldn't be a bracket at the end of the last brace D: all the above E: None of these
Question #7
Write a program that will prompt the user to enter an integer. The program should square the number and print back out the squared number. Repeat this process until 0 is entered as input.