nested Loop Printing

hello i am working on a code snippet that needs to print something like this

YXXXX
YXXX
YXX
YX
Y

my source code is

#include <iostream>
using namespace std;
int main()
{

int x=9;

for (int i=5; i <= x; i++)
{
cout<< "Y";
for (int k=i; k<=i; k++)
{
cout<< "X";
}
}
return 0;
}

and my results keep coming out the same

YXYXYXYXYX

i know my problem is within the inner loop but i just cant seem to figure it out any help would be appreciated

-AJ
i figured out what i was doing wrong but i would love any advice that anyone could give on a better solution

#include <iostream>
using namespace std;
int main()
{

int x=9;

for (int i=4; i < x; i++)
{
cout<< "Y";
for (int k=i; k<=7; k++)
{
cout<< "X";
}
cout<<endl;
}
return 0;
}


this prints what i needed

-AJ
closed account (NAUoizwU)
// How about user determined lines
// Only started learning C++ last week, just tinkering.

#include <iostream>

using namespace std;

int main()
{
int Lines;

cout << "How many lines: ";
cin >> Lines;
cout <<"\n\n";

for (int yCount=1; yCount < (Lines+1); yCount++)
{
cout<< "Y";
for (int xCount=yCount; xCount<= (Lines-1); xCount++)
{
cout<< "X";
}
cout<<endl;
}
return 0;
}
Topic archived. No new replies allowed.