Question
LAB 5.3 Working with Looping Structures Step 1: Remove tryIt5B.cpp from the project and add the loops.cpp program in your Lab5 folder to the project.
LAB 5.3 Working with Looping Structures
Step 1: Remove tryIt5B.cpp from the project and add the loops.cpp program in your Lab5 folder to the project. Below is a copy of the source code for int main().
1 // Lab 5 - loops.cpp Working with looping structures 2 // PUT YOUR NAME HERE.
6 int main() 7 { 8 cout << "PUT YOUR NAME HERE. "; 9 cout << " Activity 1 ========== "; 10 // Change the following do-while loop to a while loop. 11 int inputNum; 12 do 13 { cout << "Enter a number (or 0 to quit): "; 14 cin >> inputNum; 15 } while (inputNum != 0); 16 17 cout << " Activity 2 ========== "; 18 // Change the following while loop to a do-while loop. 19 char doAgain = 'y'; 20 while (doAgain == 'Y' || doAgain == 'y') 21 { cout << "Do you want to loop again? (y/n) "; 22 cin >> doAgain; 23 } 24 25 cout << " Activity 3 ========== "; 26 // Change the following while loop to a for loop. 27 int count = 0; 28 while (count++ < 5) 29 cout << "Count is " << count << endl; 30 31 cout << " Activity 4 ========== "; 32 // Change the following for loop to a while loop. 33 for (int x = 5; x > 0; x--) 34 cout << x << " seconds to go. "; 35 36 cout << " Activity 5 ========== "; 37 // Make the following changes to the code below that uses nested loops: 38 // 1. The code is supposed to print 3 lines with a $ and 5 stars on 39 // each line, but it contains a logic error. Find and fix the error. 40 // 2. Then revise the code to follow each $ with just 4 stars, like this: 41 // $**** 42 // $**** 43 // $**** 44 // 3. Change the two loop control variable names to be more descriptive. 45 for (int i = 1; i <= 3; i++) 46 { cout << '$'; 47 for (int j = 1; j <= 5; j++) 48 cout << '*'; 49 } 50 cout << endl; 51
52 return 0;
53 }
Step 2: Put your name on lines 2 and 8. Then compile and run the program to see what it does.
When Activity 1 asks for inputs use the following inputs:
5
2
0
When Activity 2 asks for input use the following inputs:
y
Y
n
Print a copy of the output to compare to the output the program creates after you revise it.
Step 3: Make all the modifications requested in the source code. Then recompile the program and rerun it. If you have done everything correctly, you should get the same results as before for Activities 1 4. You should get the following output for Activity 5:
$****
$****
$****
Step 4: If your professor asks you to do so, print the final, revised source code and the output to hand in.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
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