Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

question about forming X shape in C++

$
0
0
hey, can you guys please help me figure out how to make an x shape. so far, all i can do is get the one diagonal side with the following code, but i can't get the other side. i'd really appreciate any help. i really suck at for loops.
thanks a lot

#include <iostream>
using namespace std;

int main()
{
int number;


cout<< "Enter a number: ";
cin>> number;

while (number< 2 || number% 2 == 0)
{
cout << "Invalid response. Enter an odd number greater than or equal to 2:";
cin>> number;
}

for( int lineNum=0; lineNum<number; lineNum++)
{
cout <<"*";
for (int i=0; i<number-lineNum; i++)
cout<<" ";
cout<<endl;

for (int x= 0; x<= lineNum; x++)
cout<< " ";

}





cout<< endl;
system( "Pause");
return 0;

}


Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>