Sovi.AI - AI Math Tutor

Scan to solve math questions

QUESTION IMAGE

positive integer numinsects is read from input. organize the lines of c…

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;
}

Explanation:

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;

Answer:

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;
}