a) The following code implements a for loop, a do while loop, and a while loop. There are stubs for four additional loops. You are to add the code necessary to implement the missing loops as indicated by the comments. When adding code for a for loop, you must fill in all three parts in the for statement, i.e. the parts inside the parenthesis. Outputs for the three versions of Loop A should be identical. The three versions of Loop B should behave in the same way. Outputs for the three versions of Loop C should be identical.
#include "std_lib_facilities_4.h"
int main(int argc, char* argv[]) {
cout << "Loop A (for version)" << endl;
for (int i=0; i<5; i++) {
cout << i << endl;
}
cout << "Loop A (while version)" << endl;
// Add while loop code
cout << "Loop A (do while version)" << endl;
// Add do while loop code
cout << "Loop B (do while version)" << endl;
int i;
do {
cout << "Enter a number less than 100 (Greater than 100 to exit):" << endl;
cin >> i;
cout << i << endl;
} while (i<100);
cout << "Loop B (for version)" << endl;
// Add for loop code
cout << "Loop B (while version)" << endl;
// Add while loop code
cout << "Loop C (while version)" << endl;
int i = 20;
while (i>10) {
cout << i*2 << " ";
i-=2;
}
cout << endl << endl;
cout << "Loop C (do while version)" << endl;
// Add do while loop code
cout << "Loop C (for version)" << endl;
// Add for loop code
}
b) As a comment in the code above describe the scope of the variable i in inside and outside the body of each version of each loop.
c) What is the minimum number of iterations for each type of loop? You can put this as a comment at the top of your code.
Bro you should really at least attempt to get some working code. This isn't like one of the more advanced concepts, like classes or recursion. Loops and control structure are one of the most basic and necessary concepts in almost, if not all programming languages.
basic and necessary concepts in almost, if not all programming languages.
He/She is here asking for help, it would probably be better if you didn't bash him for not knowing how to do it. But you are definitely right about having @carl123 put some effort into the code.
@carl123 We are here to help, not to do your homework for you, explain in detail what you need help with and we will provide examples for you use to complete your own homework/assessment, But we won't do YOUR assessment and homework. That's for you to do