I received some help on it at school and this code is displaying 1 2 3 4, but I actually need
1 2 3
1 2 3
My teacher said we will not need a for loop, only two do while loops.
#include <iostream>
using namespace std;
int main ()
{
//declare variables
int nested = 1;
int outer = 1;
do //begin loop
{
do //begin loop
{
cout << nested;
cout << " ";
nested += 1;
} while (nested < 4);
outer += 1;
} while (outer <= 2);
//end while
Yes, you have an infinite loop. When you added that "nested = 1" statement, you wiped out the previous "outer += 1" statement. You didn't want to do that. You want both statements.
Oh ok I've got it now! Thank you! One more question its showing it as
1 2 3 1 2 3
where am I needing my endl at? I tried it many places and its spacing it at the wrong places. I tried after my cout << nested?