Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Calculation for project
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
prefx




PostPosted: Mon Jan 12, 2009 7:55 pm   Post subject: Calculation for project

Hi i have learned the basics of turing... but i am having lots of troubles trying to calculate something use a "real" variable.

Turing:

%Variables -----
var price1,price2:real
var day, hour, year:real

price1:= 84.00
price2:= 0.90
day:= 0
hour:= 0
year:= 0

loop

hour:= hour +1
day:= hour /24
year:= day /365
price1:= price1 * price2


exit when year>= 4
end loop
put "You will have ", price1, " on year ", year, "."


I keep getting an exponential number... when i should be getting a number lower than 100. I believe i have the loop correct... but i am not totally sure.. any ideas of what i should do?

** The competition for our product is very fierce. The prices will decrease steadily each year. If the present selling price for the product is $84.00 and will drop by 10% every year, how much will the product sell for in 4 years?
e.g. next years price = current years price * 0.90
price next year = 84.00 * 0.90
= 75.60

price in 2 years = 75.60 * 0.90
= 68.04

Print a single line that will give how many years ahead we are looking and what is our expected selling price. **


This is the assignment im doing... if this gives you a better idea of what i can do.
thanks!


Mod Edit: Please use [code] or [syntax] tags when posting code, thanks.
Sponsor
Sponsor
Sponsor
sponsor
TheGuardian001




PostPosted: Mon Jan 12, 2009 8:02 pm   Post subject: Re: Calculation for project

is there any particular reason that you're even bothering to calculate based on hours and days? there's no need to scale the program down that much. you will probably be able to do this much easier if you just use years.
prefx @ Mon Jan 12, 2009 7:55 pm wrote:

e.g. next years price = current years price * 0.90
price next year = 84.00 * 0.90
= 75.60

price in 2 years = 75.60 * 0.90
= 68.04

that is essentially the whole program written for you, in pseudocode, in your own post. just take the starting price, multiply by 0.9, and repeat with the result.
prefx




PostPosted: Mon Jan 12, 2009 8:06 pm   Post subject: Re: Calculation for project

I realize im not using the days, years ect, but i simply need it for looping so i have some basis for now
there are more parts to my assignment... so they will be used later on.... but i realized the mistake...

The equatition simply needed to be out of the loop... haha
it couldnt have got any simpler i guess... but help works too Mr. Green
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 3 Posts ]
Jump to:   


Style:  
Search: