Assistance with homework prob (pseudocode)

Ok.. brief recap for ya, I'm new, I enjoy programming so far.. I like to learn and I recently started taking online classes to get a solid foundation. I'm currently taking a logic/design class... so there's no language syntax involved here, just pseudocode. I've been doing well for the last 5 weeks up until we got this problem to solve. I was hoping you guys could help me understand how to put this all together. Here's the problem:

(A Human Resources Department wants a report that shows its employees the benefits of saving for retirement. Produce a report that shows 12 predicted retirement account values for each employee -the values if the employee saves 5, 10, or 15 percent of his or her annual salary for 10, 20, 30 or 40 years. The department maintains a file in which each record contains the name of an employee and the employee's current annual salary. Assume that savings grow at a rate of 8 percent per year.

Write the pseudocode for this program)

This week was learning about using different types of pretest/postest loops For, while, do until, etc.. etc.. I understand what they do, but still have trouble knowing when to use certain types with whatever situations at hand. The teacher threw me a few hints of how the code should be written, which I guessed would be three nested loops, but one would handle counting 1-40 years, one to handle the salary + saved % + interest rate, and the most inner to handle the print statements.

I have a huge problem understanding how to write this so that the interest rate is calculated correctly for 39 of the 40 years (since no interest is added on the first deposit), and only outputting when years 10,20,30,40 are reached. Along with that how can I get a loop to change what percentage saved is without making an entirely new loop? The only way I have been able to do this problem is by using three different For loops that have an if statement for the different years to print.

I'm just totally stumped on this, i know this much be easy once it's down on paper... i feel stupid atm. :( Hope you guys can help me out here.
Last edited on
I have a huge problem understanding how to write this so that the interest rate is calculated correctly for 39 of the 40 years (since no interest is added on the first deposit), and only outputting when years 10,20,30,40 are reached.

Well, then you better get to it. What are you doing on the interwebs?
After two days of attempting this, I'm resorting to the i-net to hopefully hear some constructive responses. Guess I'm 0-1 atm.
Sigh...
This thing's a piece of cake, I don't see anything here particularly difficult.
What do you have so far?
I know there's probably a few print commands and other things that are not present yet, but im just trying to arrange the main functions of the loops to work correctly first...:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
yearCounter = 10
while yearCounter <=40
     savingsRateCounter = .05
          while rateCounter <= .15
               interestCounter = 1
                    while interestCounter <=10
                         savings = savings+savings*interestRate
                         interestCounter = interestCounter +1
                    endwhile
                    savingsRateCounter = savingsRateCounter + .05
          endwhile
          yearCounter = yearCounter + 10
endwhile
print results //whatever
read empRecord //reads the next employee record to be tested

return



Now the problems I "think" i have so far is:
- I don't see how the values of 5,10,15% are being used in the savings=savings+savings*interestRate, unless I can use the value of the counter variable???

- I think my printing statements I need have to be done from within the inner most loop.

- And as far as the inner loops processing goes.. all 40 calculations are being added with the 8% interest rather than 39. As it stands now in example my 10th year at say, 5% is going to have the interest of the 11th year because the very first year is getting interest added to it without spending a year earning interest yet.


Am I on the right track at least lol?
Last edited on
Am I on the right track at least lol?

No. Furthermore, you suck (my mercilessness is legendary).

I'll now tell you about the modulo operator, usually written as '%'. It computes the remainder of a division. Useful to know if a number is divisible by another.
For example, for i%10:
i: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 ...
i%10: 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 ...

So, to check if a number is divisible by 10, just see if n%10 equals zero. Note that 0%x==0 and that x%0 is equivalent to x/0.

First, you'll have an outer loop to go through all the employees, then another loop for annual savings of .05, .1, and .15 (percentages are for pea accountants. Programmers use units), and yet another loop for each year. Inside this loop, you will use either savings=(savings+salary*saving_rate)*1.08 or savings=savings*1.08+salary*saving_rate, depending on the order that the 8% is applied. AFTER this calculation, you must conditionally print the current savings. I'll leave the condition to you.
(my mercilessness is legendary).


Funny, it must be your legend that sucks, because I've never heard of you before. Given this "is" the beginners forum (and I'm a beginner, so I should suck), and from what I can tell from your education, I would assume you're an adult and should act like one. I will continue to address your attitude issues as they persist if you really want to play that game.......You don't have to help me if this is so annoying to you. There's other fish in the sea. In the mean time back to the real issue:


First, you'll have an outer loop to go through all the employees, then another loop for annual savings of .05, .1, and .15 (percentages are for pea accountants. Programmers use units), and yet another loop for each year. Inside this loop, you will use either savings=(savings+salary*saving_rate)*1.08 or savings=savings*1.08+salary*saving_rate, depending on the order that the 8% is applied. AFTER this calculation, you must conditionally print the current savings. I'll leave the condition to you.


Thanks for this explanation. I'll go back and re-apply this logic, thanks.
Funny, it must be your legend that sucks, because I've never heard of you before. Given this "is" the beginners forum (and I'm a beginner, so I should suck), and from what I can tell from your education, I would assume you're an adult and should act like one. I will continue to address your attitude issues as they persist if you really want to play that game.......You don't have to help me if this is so annoying to you. There's other fish in the sea. In the mean time back to the real issue:

Oh, so that's how it is, isn't it? I sprinkle some lulz on an explanation you should have received from your teacher or from 50 million different places on the Internet and you insult me? Guess what, jackass? I'm not the one seeking help. You are. So even if I *was* being serious, you're the one who needs to be polite, not me. If you insult someone who's trying to help you, you're either a fool or don't really need help.
In either case, good day to you, sir.
No. Furthermore, you suck (my mercilessness is legendary).


This was a bit uncalled-for IMO.

So even if I *was* being serious, you're the one who needs to be polite, not me. If you insult someone who's trying to help you, you're either a fool or don't really need help.


Why shouldn't you be polite? There is no reason to take a condescending approach to answering someones question. As stated in the OP, this person is new and just learning about loops. His question was well written and he did provide a fair amount of information.

Programming doesn't come naturally to everyone. Especially if you are not in a classroom environment.

This week was learning about using different types of pretest/postest loops For, while, do until, etc.. etc.. I understand what they do, but still have trouble knowing when to use certain types with whatever situations at hand.


A for-loop is used when you know the bounds of your condition and the condition can be changed through an increment or decrement.

e.g for interger i is 0 to 100

A while-loop is used for an unknown number of loops. You will test until a condition is true, but you generally do not know how many runs through before this is the case.

while (something is false) {
do stuff
do more stuff
if (something happened) then
something is now true
}

do-while is the same as a while loop, except that instead of checking condition then running, it'll do a run first then check the condition.
Last edited on
(A Human Resources Department wants a report that shows its employees the benefits of saving for retirement. Produce a report that shows 12 predicted retirement account values for each employee -the values if the employee saves 5, 10, or 15 percent of his or her annual salary for 10, 20, 30 or 40 years. The department maintains a file in which each record contains the name of an employee and the employee's current annual salary. Assume that savings grow at a rate of 8 percent per year.


You need to think of it more like a flow-chart.

1
2
3
4
5
6
7
8
1. Load Employee Records from File
2. Loop through Employees
2_. Loop through 1-3 (multiply by 5 to get 5, 10 or 15)
2__. Loop through 1-40
2___. Increase Savings
2___. If Mod(10) = 0, Print Savings

- = inside loop


That's not pseudo, but is a rough flow of how the application would be built. Unless I have over-looked something in my 30sec read.

Edit: Once you have the flow sorted, then you can write the pseudo that represents it
Last edited on
Topic archived. No new replies allowed.