jay-r wrote: > --- In [email protected], John Gaughan <[EMAIL PROTECTED]> wrote: >> Paul Herring wrote: >>> I was not inclined to read the original code because it was > unreadable. >>> >> I copied and pasted it into my dev environment and reformatted it. > The >> question was coherent and seemed genuine, so it was worth the few >> seconds. I was hoping he would help explain his code and what it is >> doing, and in the process discover what it is not doing. >> >> Sort of like when people stop by my desk and work asking a > question, and >> in the process of explaining the problem they find the solution. >> >> -- >> John Gaughan > > As a beginner, I have a hard time solving this exercise. As I > mentioned before that I can make a square & rectangle but can't > figure out how to do a diagonal line using looping. > > That's pretty much the reason why I posted the code hoping that > someone will help but.... > > Jay
You have to think of the screen as a 2-dimensional grid that has to be filled from top-to-bottom, left-to-right. Your challenge is to figure out how many spaces on a given line you have to output to get to the right position on the screen before outputting asterisks. It might be easier to start with an upside-down triangle. You know exactly how many spaces to use for the first line (0). The next line is just one more than that (1). The next line is one more than the previous (2). And so on... The challenge then becomes an issue of coming up with a mathematical formula that calculates the middle of the triangle to get a number (integer) that represents the correct number of spaces to output for the first line. Of course, if you can do this first, then you don't need the upside-down triangle. -- Thomas Hruska CubicleSoft President Ph: 517-803-4197 *NEW* MyTaskFocus 1.1 Get on task. Stay on task. http://www.CubicleSoft.com/MyTaskFocus/
