psudocode....loops

trouble with loops

Page 1 of 1

11 Replies - 4752 Views - Last Post: 18 February 2006 - 06:08 PM Rate Topic: -----

#1 erniebax  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 18-February 06

psudocode....loops

Posted 18 February 2006 - 03:35 PM

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

Is This A Good Question/Topic? 0
  • +

Replies To: psudocode....loops

#2 Nova Dragoon  Icon User is offline

  • The Innocent Shall Suffer, Big Time
  • member icon

Reputation: 36
  • View blog
  • Posts: 6,169
  • Joined: 16-August 01

Re: psudocode....loops

Posted 18 February 2006 - 03:59 PM

Could you show us what you've gotten so far?
Was This Post Helpful? 0
  • +
  • -

#3 erniebax  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 18-February 06

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

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

Was This Post Helpful? 0
  • +
  • -

#4 Nova Dragoon  Icon User is offline

  • The Innocent Shall Suffer, Big Time
  • member icon

Reputation: 36
  • View blog
  • Posts: 6,169
  • Joined: 16-August 01

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.
Was This Post Helpful? 0
  • +
  • -

#5 erniebax  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 18-February 06

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?
Was This Post Helpful? 0
  • +
  • -

#6 Amadeus  Icon User is offline

  • g+ + -o drink whiskey.cpp
  • member icon

Reputation: 248
  • View blog
  • Posts: 13,506
  • Joined: 12-July 02

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.
Was This Post Helpful? 0
  • +
  • -

#7 erniebax  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 18-February 06

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>
Was This Post Helpful? 0
  • +
  • -

#8 Nova Dragoon  Icon User is offline

  • The Innocent Shall Suffer, Big Time
  • member icon

Reputation: 36
  • View blog
  • Posts: 6,169
  • Joined: 16-August 01

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....
Was This Post Helpful? 0
  • +
  • -

#9 Amadeus  Icon User is offline

  • g+ + -o drink whiskey.cpp
  • member icon

Reputation: 248
  • View blog
  • Posts: 13,506
  • Joined: 12-July 02

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.
Was This Post Helpful? 0
  • +
  • -

#10 erniebax  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 18-February 06

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?
Was This Post Helpful? 0
  • +
  • -

#11 Amadeus  Icon User is offline

  • g+ + -o drink whiskey.cpp
  • member icon

Reputation: 248
  • View blog
  • Posts: 13,506
  • Joined: 12-July 02

Re: psudocode....loops

Posted 18 February 2006 - 06:05 PM

Close...try
 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.
Was This Post Helpful? 0
  • +
  • -

#12 erniebax  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 18-February 06

Re: psudocode....loops

Posted 18 February 2006 - 06:08 PM

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

thx again

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

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1