Hi I read the guidelines about homework questions and it says to clearly state that it is homework. This is homework, I have spent the last 45 minutes trying over and over again. I've hit a wall and need help.
My assignment was to take this code that came from a double For loop and convert it into a while loop nested into a for loop. I have successfully completed that. However, the 3rd part is to take that code and make the outer for loop into a do while loop. The output needs to increment a "#" each line like so if the input was "4"
#
##
###
####
Below is my code that I wrote that I need to make the outer for loop into a do while loop:
int main()
{
int side;
cout << "Enter a number: ";
cin >> side;
for (int i = 0; i < side; i++)
{
int j = i;
while(j >= 0)
{
cout << "#";
j--;
}
cout << "\n";
}
}
This is my attempt so far:
int main()
{
int side;
int i;
cout << "Enter a number: ";
cin >> side;
int j=side;
do
{
while(j >= 0)
{
cout << "#";
j--;
}
cout << "\n";
i++;
}
while(j >= side);
}
My teacher said as long as the code is explained and I understand how it works that it's okay. Any help would be much appreciated. Thanks.
i++;in your loop?