[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

pseudocode question

Posted on 2008-11-09
5
Medium Priority
?
1,018 Views
Last Modified: 2012-05-05
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
Comment
Question by:VinnyG3
  • 2
  • 2
5 Comments
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 22917777
The only thing that I notice is that yearCounter is not incremented at all.
0
 
LVL 59

Accepted Solution

by:
Chris Bottomley earned 1000 total points
ID: 22917787
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
 
LVL 76

Assisted Solution

by:GrahamSkan
GrahamSkan earned 1000 total points
ID: 22917797
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
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 22917801
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
 

Author Closing Comment

by:VinnyG3
ID: 31514891
Thanks guys
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question