dimanche 27 octobre 2019

image made from dots and letters c++

very basic Q as I just started with coding but I stuck at some point and have 0 ideas what to do.

I need to write code to get diamond shape made from dots and X letters, size based on a value (n) provided by the user, (3 ≤ n ≤ 80).

for example:

enter image description here

As I mentioned - I have almost 0 experience so all I could get is is this shape for n=6

enter image description here

height is ok, same as widht but unfortunately, the amount of X's and placement isn't correct :/

my code:

int h;
cerr << "Provide size of diamond: ";
cin >> h;


for (int i = 1; i <= h; i++)
{
    for (int k = 1 ; k <= h-i ; k++)
    {
        cout << ".";
    }
    for (int j = 1; j <= i ; j++)
    {
        cout << "X";
    }
    cout << endl;

Thank you all good people who will help mi with this one :)

Aucun commentaire:

Enregistrer un commentaire