• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1041
  • Last Modified:

pseudocode question

I have some code that has some bugs in it. A standard mortgage is paid monthly over 30 years. This program is intended to print 360 payment coupons for a new borrower. Each coupon lists the month number, year number, and a friendly mailing reminder. Can you please help me fix this pseudocode.
start
     num MONTHS = 12
     num YEARS = 30
     string MSG = "remember to allow 5 days for mailing"
     num monthCounter = 1
     num yearCounter = 1 
     while yearCounter <= YEARS
           while monthCounter <= MONTHS
                 Print monthCounter, yearCounter, MSG
                 monthCounter = monthCounter + 1
            endwhile
     end while
stop

Open in new window

0
VinnyG3
Asked:
VinnyG3
  • 2
  • 2
2 Solutions
 
GrahamSkanRetiredCommented:
The only thing that I notice is that yearCounter is not incremented at all.
0
 
Chris BottomleySoftware Quality Lead EngineerCommented:
Hello VinnyG3,

Year counter needs to be incremented and month counter reset i.e. as below

Regards,
Chris
start
     num MONTHS = 12
     num YEARS = 30
     string MSG = "remember to allow 5 days for mailing"
     num monthCounter = 1
     num yearCounter = 1 
     while yearCounter <= YEARS
           while monthCounter <= MONTHS
                 Print monthCounter, yearCounter, MSG
                 monthCounter = monthCounter + 1
            endwhile
            yearCounter = yearCounter + 1
            monthCounter = 1
    end while
stop

Open in new window

0
 
GrahamSkanRetiredCommented:
Also monthCounter is not being restarted, so it needs to be set to 1 for each year

Start
     num MONTHS = 12
     num YEARS = 30
     string MSG = "remember to allow 5 days for mailing"
     
     num yearCounter = 1
     While yearCounter <= YEARS
            num monthCounter = 1
             While monthCounter <= MONTHS
                 Print monthCounter, yearCounter, MSG
                 monthCounter = monthCounter + 1
            end while
            yearCounter = yearCounter + 1
     end while
Stop
0
 
Chris BottomleySoftware Quality Lead EngineerCommented:
You do it alternatively with for loops which ought to be easier to see:

Chris
Start
     num MONTHS = 12
     num YEARS = 30
     string MSG = "remember to allow 5 days for mailing"
     num monthCounter = 1
     num yearCounter = 1
     For yearCounter = 1 To YEARS
           For monthCounter = 1 To MONTHS
                 Debug.Print monthCounter, yearCounter, MSG
           Next
     Next
Stop:

Open in new window

0
 
VinnyG3Author Commented:
Thanks guys
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now