Hard Light Productions Forums

Off-Topic Discussion => Programming => Topic started by: Kosh on November 22, 2008, 05:33:28 am

Title: simple c++ question
Post by: Kosh on November 22, 2008, 05:33:28 am
Our assignment is to make the following to appear on screen:

         *
      * * *
   * * * * *         
* * * * * * *
      * * *
      * * *
      * * *

Other than brute forcing it, is there another way with loops? I was thinking nested loops but I'm not entirely clear on how to increment this.....
Title: Re: simple c++ question
Post by: Spicious on November 22, 2008, 06:00:08 am
Try thinking about how the number of *s per line changes as you go down and also the number of spaces before the *s start on each line. Of course, this is only worth doing if the arrow size is variable; otherwise, you might as well just print a string literal.
Title: Re: simple c++ question
Post by: blackhole on November 22, 2008, 05:17:05 pm
#include <iostream>

int main()
{
cout << "         *\n
      * * *\n
   * * * * *\n         
* * * * * * *\n
      * * *\n
      * * *\n
      * * *\n";
return 0;
}

If an assignment is only going to take you 15 seconds to brute force, you might as well brute force it.
Title: Re: simple c++ question
Post by: Kosh on November 23, 2008, 09:44:01 am
Thanks.