How could I reverse the increment order?
Oct 28, 2018 at 5:48am UTC
How can i make this reverse the increment of the numbers?
for example if i input the shape for x and a size of 5 i want an output like this (dashes for spacing reference)
5---1
-2-2
--3
-4-2
5---1
instead my code ouputs this
1---1
-2-2
--3
-4-4
5---5
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
//x
switch (shape){
case 'x' :
for (int rows=-1;rows<=size;rows++) {
for (int cols=1;size>=cols;cols++){
if (rows==cols||cols==(size+1)-rows)cout<<rows;
else cout<<" " ;
}
cout<<endl;
}break ;
//b
case 'b' :
for (int rows=1;rows<=size;rows++) {
for (int cols=1;size>=cols;cols++){
if (rows==cols)cout<<rows;
else cout<<" " ;
}
cout<<endl;
}break ;
//f
case 'f' :
for (int rows=1;rows<=size;rows++) {
for (int cols=1;size>=cols;cols++){
if (cols==(size+1)-rows)cout<<rows;
else cout<<" " ;
}
cout<<endl;
}break ;
}
//Draw the shape
//Exit
return 0;
}
Oct 28, 2018 at 8:30am UTC
Use an
if ... else if ... else
structure instead of your current lines 6 and 7.
One will write out rows, the other 'something' - rows.
You have a strange row range on line 4.
DON'T delete your posts after getting an answer. You have done this in multiple threads.
Topic archived. No new replies allowed.