Nov 10, 2009 at 5:23pm UTC
I can't figure out what I need to do to display these numbers in the correct order
//Displays the following pattern of numbers
//2 4 6
//8 10 12
//14 16 18
//20 22 24
#include <iostream>
using std::cout;
using std::cin;
using std::endl;
int main()
{
int number = 0;
for (int outer = 1; outer < 4; outer = outer + 1)
for (int inner = 1; inner < 5; inner = inner + 1)
{
number = number + 2;
cout << number << endl;
}
cout << endl;
return 0;
}
Nov 10, 2009 at 5:39pm UTC
Replace the first endl with a whitespace character ( ' '
)
Add braces to include cout << endl;
in the outer loop
Please use [co de][/code] tags
Nov 10, 2009 at 7:15pm UTC
your inner loop should print one line text of text. There are three numbers per line, so it should loop 3 times.
your outer loop controls the number of lines of text to output. There are 4 lines, so it should loop 4 times.
Nov 10, 2009 at 7:24pm UTC
hahaha crap. I didn't even look at the loop condition. I knew this all along. Thanks guys!