I have this code running without any errors, but it is not displaying the correct way and I can't figure it out! I have tried so many different things! This is my code...
#include <iostream>
using namespace std;
int main ()
{
//declare variables
int nested = 1;
int outer = 1;
You will not get 1,2,3 on the same line for outer because you put endl at the end, which creates a new line.
Do not do this:
1 2 3 4
//declare variables
int nested = 1;
for (int nested = 1; nested <= 2; nested += 1)
You are declaring nested two times. You are making a local variable in the for loop, but once outside the parameters, the compiler doesn't know which one YOU want to use.
If you want a newline after 1, 2, and 3, end the while loop after it's done with outer. Now, print a newline and begin the for loop.
I still didn't figure out the BBCode...but this is my code that I have and it is still showing
1 2 3
1
I have been changing just about everything to see if I could find a fix
#include <iostream>
using namespace std;
int main ()
{
//declare variables
int outer = 1;
int nested = 1;
Well, there's a lot of extra code in there that isn't needed.
But I'd suggest you focus on this, which I posted a while ago:
the inner loop should repeat 3 times and the outer loop should repeat 2 times.
Now look at the code you have above. In fact you no longer have an outer and an inner loop. Instead there are two completely independent loops, one after the other. (I think some of the previous suggestions pointed in that direction, but in my opinion that was misguided and wrong advice).
the inner loop should repeat 3 times and the outer loop should repeat 2 times.
Chervil is right. Sorry about that.
If you look at the two lines:
1 2 3
1 2 3
You'll see that they are repeating, and the only thing that is changing is the position where it starts. So the outer loop ends the line, and the inner loop outputs the numbers.
while the outer loop is less then 3
for each nested and nested is less then 4 output the value of nested plus a space.
end the line in the outer loop.
increment outer.
loop