hi guys.....im new new here and i had a question....i just started college and in my concepts of programming class...i'm having a little trouble with pseudocode.....mainly the loop sructure......we just finished IFTHENELSE structure which i had no problem with, but the DOWHILE structure confuses me....now, i'm not here to ask anybody to do my homework or anything but i just want to ask for a little help setting the pseudocode up.......here is an example problem.

Manhatten Island was purchased in 1626 for 24$. If those early buyers had invested the same amount at 2 percent, compounded anually, how much would their investment be worth today?

I would appreciate any help with writing the pseudocode for this problem...

thanks

## 11 Replies - 5006 Views - Last Post: 18 February 2006 - 06:08 PM

##
**Replies To:** psudocode....loops

### #2

## Re: psudocode....loops

Posted 18 February 2006 - 03:59 PM

Could you show us what you've gotten so far?

### #3

## Re: psudocode....loops

Posted 18 February 2006 - 04:43 PM

Start

Count= 2006-1626

profit = 24.00 * .02

DOWHILE count >0

How do i keep acumulating the profit to get a total investment worth at the end>.....or how do i keep adding the yearly profit to the next year...etc

Count= 2006-1626

profit = 24.00 * .02

DOWHILE count >0

How do i keep acumulating the profit to get a total investment worth at the end>.....or how do i keep adding the yearly profit to the next year...etc

This post has been edited by **erniebax**: 18 February 2006 - 04:46 PM

### #4

## Re: psudocode....loops

Posted 18 February 2006 - 04:48 PM

What you need to do, is in a loop iteratio, calulate the profit for that year from the previous year's principle. Then add the profit to the priniciple, and go through the loop again for the next year.

Tell me if that made sense.

Tell me if that made sense.

### #5

## Re: psudocode....loops

Posted 18 February 2006 - 05:09 PM

it makes sense...however i still dont know how exactly how iset it up......i'm using this problem as a guide on how to do the other problems........are u saying i need to set up another variable for previous year?

### #6

## Re: psudocode....loops

Posted 18 February 2006 - 05:16 PM

You can keep a running total...call it x.

To begin, x is 24, the principal...at the end of that year, x is 24 plus 2 percent (the interest). x is now the new principal for the next year.

Repeat for each year between 1626 and 2006.

To begin, x is 24, the principal...at the end of that year, x is 24 plus 2 percent (the interest). x is now the new principal for the next year.

Repeat for each year between 1626 and 2006.

### #7

## Re: psudocode....loops

Posted 18 February 2006 - 05:20 PM

how about this?

Start

Count= 2006-1626

profit = 24.00 * .02

DOWHILE count >0

newprofit = 24.00 * .02

totalinvestment = profit + newprofit

i know this isnt right...but i think im getting close.....i cant figure out how to keep accumulating the profit.........i'm missing something or maybe i dont need the newprofit........ugh...<sigh>

Start

Count= 2006-1626

profit = 24.00 * .02

DOWHILE count >0

newprofit = 24.00 * .02

totalinvestment = profit + newprofit

i know this isnt right...but i think im getting close.....i cant figure out how to keep accumulating the profit.........i'm missing something or maybe i dont need the newprofit........ugh...<sigh>

### #8

## Re: psudocode....loops

Posted 18 February 2006 - 05:26 PM

technically you dont need "profit" or "newprofit". Just a prinicple variable.

The trick of this, is to build off the variables you set in the last year.

Here is the loop unrolled, what you would have to write out with out the loop to solve this problem:

X=24 //initial principle

X= X + (X*.02) // Prinicple + instrest on principle for year 1

X = X + (X * .02) //principle + intrest on priciple for year 2

X = X + (X * .02) //principle + intrest on priciple for year 3

X = X + (X * .02) //principle + intrest on priciple for year 4

X = X + (X * .02) //principle + intrest on priciple for year 5

etc....

The trick of this, is to build off the variables you set in the last year.

Here is the loop unrolled, what you would have to write out with out the loop to solve this problem:

X=24 //initial principle

X= X + (X*.02) // Prinicple + instrest on principle for year 1

X = X + (X * .02) //principle + intrest on priciple for year 2

X = X + (X * .02) //principle + intrest on priciple for year 3

X = X + (X * .02) //principle + intrest on priciple for year 4

X = X + (X * .02) //principle + intrest on priciple for year 5

etc....

### #9

## Re: psudocode....loops

Posted 18 February 2006 - 05:26 PM

You don't need the newprofit...your new total will always be your old total plus two percent of your old total.

### #10

## Re: psudocode....loops

Posted 18 February 2006 - 05:58 PM

Start

Count= 2006-1626

principal = 24

DOWHILE count >0

newprincipal = (principal *.02) + newprincipal

ENDO

newprincipal = total investment

Write "total investment"

Stop

Would this work?

Count= 2006-1626

principal = 24

DOWHILE count >0

newprincipal = (principal *.02) + newprincipal

ENDO

newprincipal = total investment

Write "total investment"

Stop

Would this work?

### #11

## Re: psudocode....loops

Posted 18 February 2006 - 06:05 PM

Close...try

The value of principal will be adjusted each time through the loop...the first loop, it is 24, so the new principal becomes 24 plus 2 percent of 24...therefore, it is 24.48...the next time through, the new pricinpal is 24.48 plus two percent of 24.48...see how it goes?

As an FYI, you'll need to decrement count in there somewhere.

Start Count= 2006-1626 principal = 24 DOWHILE count >0 principal = (principal *.02) + principal ENDO Write "principal" Stop

The value of principal will be adjusted each time through the loop...the first loop, it is 24, so the new principal becomes 24 plus 2 percent of 24...therefore, it is 24.48...the next time through, the new pricinpal is 24.48 plus two percent of 24.48...see how it goes?

As an FYI, you'll need to decrement count in there somewhere.

### #12

## Re: psudocode....loops

Posted 18 February 2006 - 06:08 PM

I appreciate the help guys.....it helped out alot

thx again

thx again

This post has been edited by **erniebax**: 18 February 2006 - 06:10 PM

Page 1 of 1