- #1
magnifik
- 360
- 0
I am trying to create a code that does the exact same thing as this does
but using a do while loop instead. what i have so far is this
the only problem is on the last line the "#" signs line up instead of being diagonal. any help on how to fix this??
Code:
#include <iostream>
using namespace std;
int main()
{
int len;
cout << "Enter a number: ";
cin >> len;
for (int i = 0; i < len; i++)
{
for (int j = i+1; j < len; j++)
{
cout << ' ';
}
cout << "#\n";
}
}
but using a do while loop instead. what i have so far is this
Code:
#include <iostream>
using namespace std;
int main()
{
int len;
cout << "Enter a number: ";
cin >> len;
for (int i = 0; i < len; i++)
{
int j = i+1;
do
{
cout << ' ';
j++;
}
while (j < len);
cout << "#\n";
}
}
the only problem is on the last line the "#" signs line up instead of being diagonal. any help on how to fix this??