QUESTION IMAGE
Question
positive integer numinsects is read from input. organize the lines of code to create a while loop that executes while numinsects is less than 200. in each iteration:
- print numinsects followed by a space.
- update numinsects with numinsects multiplied by 2.
after the loop, print a newline.
ex. if the input is 16, then the output is:
16 32 64 128
how to use this tool
unused
}
numinsects = numinsects * 2;
cout << endl;
while (numinsects < 200) {
cout << numinsects << \ \;
main.cpp
load default template...
#include <iostream>
using namespace std;
int main() {
int numinsects;
cin >> numinsects; // must be >= 1
return 0;
}
Step1: Add while loop condition
while (numInsects < 200) {
Step2: Print current numInsects
cout << numInsects << " ";
Step3: Update numInsects value
numInsects = numInsects * 2;
Step4: Close the while loop
}
Step5: Print newline after loop
cout << endl;Snap & solve any problem in the app
Get step-by-step solutions on Sovi AI
Photo-based solutions with guided steps
Explore more problems and detailed explanations
The completed main.cpp code is:
#include <iostream>
using namespace std;
int main() {
int numInsects;
cin >> numInsects; // Must be >= 1
while (numInsects < 200) {
cout << numInsects << " ";
numInsects = numInsects * 2;
}
cout << endl;
return 0;
}