Welcome to Dream.In.Code
Getting Help is Easy!

Join 132,628 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,054 people online right now. Registration is fast and FREE... Join Now!




psudocode....loops

 
Reply to this topicStart new topic

psudocode....loops, trouble with loops

erniebax
post 18 Feb, 2006 - 02:35 PM
Post #1


New D.I.C Head

*
Joined: 18 Feb, 2006
Posts: 6


My Contributions


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
User is offlineProfile CardPM

Go to the top of the page

Nova Dragoon
post 18 Feb, 2006 - 02:59 PM
Post #2


The Innocent Shall Suffer, Big Time

Group Icon
Joined: 16 Aug, 2001
Posts: 6,128



Thanked 4 times

Dream Kudos: 515

Expert In: Python, Linux

My Contributions


Could you show us what you've gotten so far?
User is offlineProfile CardPM

Go to the top of the page

erniebax
post 18 Feb, 2006 - 03:43 PM
Post #3


New D.I.C Head

*
Joined: 18 Feb, 2006
Posts: 6


My Contributions


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 Feb, 2006 - 03:46 PM
User is offlineProfile CardPM

Go to the top of the page

Nova Dragoon
post 18 Feb, 2006 - 03:48 PM
Post #4


The Innocent Shall Suffer, Big Time

Group Icon
Joined: 16 Aug, 2001
Posts: 6,128



Thanked 4 times

Dream Kudos: 515

Expert In: Python, Linux

My Contributions


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.
User is offlineProfile CardPM

Go to the top of the page

erniebax
post 18 Feb, 2006 - 04:09 PM
Post #5


New D.I.C Head

*
Joined: 18 Feb, 2006
Posts: 6


My Contributions


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?
User is offlineProfile CardPM

Go to the top of the page

Amadeus
post 18 Feb, 2006 - 04:16 PM
Post #6


g++ -o drink whiskey.cpp

Group Icon
Joined: 12 Jul, 2002
Posts: 12,176



Thanked 33 times

Dream Kudos: 25
My Contributions


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.
User is offlineProfile CardPM

Go to the top of the page

erniebax
post 18 Feb, 2006 - 04:20 PM
Post #7


New D.I.C Head

*
Joined: 18 Feb, 2006
Posts: 6


My Contributions


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>
User is offlineProfile CardPM

Go to the top of the page

Nova Dragoon
post 18 Feb, 2006 - 04:26 PM
Post #8


The Innocent Shall Suffer, Big Time

Group Icon
Joined: 16 Aug, 2001
Posts: 6,128



Thanked 4 times

Dream Kudos: 515

Expert In: Python, Linux

My Contributions


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....
User is offlineProfile CardPM

Go to the top of the page

Amadeus
post 18 Feb, 2006 - 04:26 PM
Post #9


g++ -o drink whiskey.cpp

Group Icon
Joined: 12 Jul, 2002
Posts: 12,176



Thanked 33 times

Dream Kudos: 25
My Contributions


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

Go to the top of the page

erniebax
post 18 Feb, 2006 - 04:58 PM
Post #10


New D.I.C Head

*
Joined: 18 Feb, 2006
Posts: 6


My Contributions


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


Would this work?
User is offlineProfile CardPM

Go to the top of the page

Amadeus
post 18 Feb, 2006 - 05:05 PM
Post #11


g++ -o drink whiskey.cpp

Group Icon
Joined: 12 Jul, 2002
Posts: 12,176



Thanked 33 times

Dream Kudos: 25
My Contributions


Close...try
CODE

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.
User is offlineProfile CardPM

Go to the top of the page

erniebax
post 18 Feb, 2006 - 05:08 PM
Post #12


New D.I.C Head

*
Joined: 18 Feb, 2006
Posts: 6


My Contributions


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

thx again

This post has been edited by erniebax: 18 Feb, 2006 - 05:10 PM
User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 11/23/08 03:36AM

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month