Looping shapes.

So my code is here: http://cpp.sh/7pfnv
Just ignore the rest and look at my S/Square shape.
Variable 'a' refers to the number of shapes and variable 'b' refers to the number of times I need to loop variable 'a'.
Like for example a=2 and b=5.
The shapes must show 2 + 2 + 2 + 2 + 2 = 10.
The answer of the multiplication must not be over 10 :)
I think my codes are a little messed up. :(

Anyone can kindly help me solve how to loop the "+" signs and also the square shapes? Thank you very much. :)
For some reason you are sorting a and b. Don't do that.

You need two sets of loops: one for b (to do b groups of a, separated by '+'), and inside that the loops like you have for a.

*** *** + *** *** + *** *** = *** *** *** *** *** ***
*** ***   *** ***   *** ***   *** *** *** *** *** ***
-------   -------   -------   -----------------------
  a=2       a=2       a=2     a*b=6
---------------------------
  b=3

Wrap the a loop inside a b loop. (That's two loops, on inside another -- also called "nested loops".)

The trick, of course, is those plus signs and spaces. For that you'll have to pay attention to whether or not you are on the last loop of b. (Hint, on the last loop, print a '=' instead of a '+'.)

Hope this helps.
Topic archived. No new replies allowed.