Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to increment setw?

Tags:

c++

I need to display something that looks like:

     /
    -
    /
   /
    -
    /
   /
  /
   -

I currently have the following which does not print the slashes properly.

for (int i = 1; i <= numberOfDolls; i++) {
   for(int j = 1; j <= i; j++) 
      cout << setw(numberOfDolls) << '/' << endl;
      
      cout << "-" << endl;
    }

I was thinking of using setw() to increment the slashes. Is this possible?

like image 632
wockywoad Avatar asked Sep 10 '25 08:09

wockywoad


1 Answers

I am not sure about your doubt but you will get desired output using following:

for (int i = 1; i <= numberOfDolls; i++) {
   for(int j = 1, n=numberOfDolls; j <= i; j++)
      cout << setw(n--) << '/' << endl;

      cout <<setw(numberOfDolls-1)<< "-" << endl;
    }
like image 119
Anurag Singh Avatar answered Sep 13 '25 00:09

Anurag Singh