Issue with looping forwards

后端 未结 3 1586
灰色年华
灰色年华 2021-01-26 21:03

so I\'m having an issue with my loops, where the intention is to fill through the whole months before moving to the next line, like so

     January   2000                


        
相关标签:
3条回答
  • 2021-01-26 21:21

    As Perdi Estaquel saied, you've missed one more loop.

    for (month = 1; month < 12;) {
    }
    

    only enables days output once a month, and you need to do it like this.

    for (month = 1; month < 12;) {
        // month and header output stay unchanged
    
        for (int calendarLine = 1; calenderLine <= 5; calenderLine++) {
            // your calender output here
        }
    }
    
    0 讨论(0)
  • 2021-01-26 21:28

    Your approach is a bit of a headache. I'm not saying it won't work, but nesting loops like that is too complex.

    You could define a Month class that'll have header() and getLine(int lineNumber) methods.

    You can also have a Quarter class that'll have header() and getLine(int lineNumber) methods. It'll contain three Month objects.

    You can then loop through your Quarter objects (4 in a year) and print the header followed by 6 lines.

    0 讨论(0)
  • 2021-01-26 21:41

    You are missing one loop.

    Outer loop goes from leftmost month to righmost month (3 in total). But that will give you just one line.

    You have to wrap it with another loop that will go through all the lines.

    0 讨论(0)
提交回复
热议问题