the if conditional is not working.
well I don't seem to know where the braces go?
well I put it like this but the braces are still not taking effect:
Code:for (counter = 100; counter <= 148; counter = counter + 2) { cout << counter << endl; } if (counter % 6 == 0) { cout << counter << endl; }
Like this:
Code:for (int counter = 100; counter <= 148; counter = counter + 2) { cout << counter << ' '; if (counter % 6 == 0) { cout << endl; } }
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
So I changed it to this but it chops off a number at the top:
Code:for (int counter = 100; counter <= 150; counter = counter + 2) { cout << counter << ' '; if (counter % 12 == 0) { cout << endl; } }
for my above code (#38) it shows. See how it takes away the top number. :
100 102 104 106 108
110 112 114 116 118 120
122 124 126 128 130 132
134 136 138 140 142 144
146 148 150
It does nothing of the sort. All is does is print a new line.Originally Posted by walkonwater
Look, there is no problem. The only "problem" is that you are starting from a point where there are 5 numbers in the sequence before you reach a number divisible by 12.
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
This is what my teacher told me but I don't understand how to do it.
"Perhaps you need a separate counter for the printing as you cannot guarantee that the numbers won’t be divisible by 12 prematurely! 108 is divisible by 12 which is why your first line has a problem. Might have worked if you were starting at 1 but you are starting at 100. You can have 2 counters in a for loop."
That is why I asked you to start with an example that counts from 1 to 18.Originally Posted by walkonwater
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
YesOriginally Posted by walkonwater
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)