0
Execute 10 Times
How do you get this code to execute 10 times? I can only get 3 exes. Include the for loop below in a small program named question2a.cpp and complete the program. The loop should be executed 10 times. Do not change the for loop below. Compile and run your program to see for yourself that it works. You do not have to submit this program and output. for (int i = 1; i <= n; i++) if (i < 5 && i != 2) cout << 'X';
4 Respostas
+ 9
if (i < 5 && i != 2)
corresponds to values 1, 3, and 4. This is why the print statement is only executed three times.
+ 2
Output is not 1:1 to iterations. Since you don't have to submit the code, you could change what's inside the loop and -- as it says -- prove to yourself that you have the correct number of iterations.
0
Thanks!
The question says I'm not supposed to change the FOR LOOP, but if I change the IF LOOP, it works, right? I didn't notice there's a for and an if.
if (i<12 && i !=2)
0
Now convert the for loop into a while loop and add any variable initializations that you think are necessary