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

Username:   Password: 
 RegisterRegister   
 Acceleration calculations.
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
JamesXm




PostPosted: Sat Jun 24, 2006 1:06 pm   Post subject: Acceleration calculations.

I need help with real numbers. When I run this program I wrote, rounded numbers appear.
Try this:
-start the program
-hit a to calculate acceleration
-intial speed = 0 final speed = 25 time = 10
-the answer appears as 2. but it should be 2.5

Any help is greatly appreciated. Smile

code:

View.Set ("graphics")
View.Set ("title:Acceleration Calculator - JamesXm")
var a, v1, v2, v, t : real
var whattofind : string

procedure finda
    v := v2 - v1
    a := v div t
    put "Step One:"
    put ""
    put v2, "-", v1
    put "divided by"
    put t
    put ""
    put "Step Two:"
    put ""
    put v
    put "divided by"
    put t
    put ""
    put "Step Three:"
    put ""
    put a
    put ""
    put ""
    put "Therefore, the acceleration is " ,a:2

end finda

procedure findv1

end findv1

procedure findv2

end findv2

procedure findt

end findt

put "What are you trying to find? (enter a, b, c, or d)"
put "a) Acceleration (m/s2)"
put "b) Initial Speed (m/s)"
put "c) Final Speed (m/s)"
put "d) Time (s)"
get whattofind
cls
if whattofind = "a" then
    put "Initial Speed (m/s):"
    get v1
    put "Final Speed (m/s):"
    get v2
    put "Time (s):"
    get t
    cls
    finda
elsif whattofind = "b" then
    put "Acceleration (m/s2):"
    get a
    put "Final Speed (m/s):"
    get v2
    put "Time (s):"
    get t
    cls
    findv1
elsif whattofind = "c" then
    put "Acceleration (m/s2):"
    get a
    put "Initial Speed (m/s):"
    get v1
    put "Time (s):"
    get t
    cls
    findv2
elsif whattofind = "d" then
    put "Acceleration (m/s2):"
    get a
    put "Initial Speed (m/s):"
    get v1
    put "Final Speed (m/s):"
    get v2
    cls
    findt
else
    put "Restart the program! An error has occured."
end if
Sponsor
Sponsor
Sponsor
sponsor
Delos




PostPosted: Sat Jun 24, 2006 1:15 pm   Post subject: Re: Acceleration calculations.

JamesXm wrote:

code:

a := v div t



Use '/' instead of 'div'. The div operator truncates remainders.
upthescale




PostPosted: Sat Jun 24, 2006 1:17 pm   Post subject: (No subject)

First of all at the top you have Two View.Sets. Why not just put the title in with the graphics?

View.Set("graphics;title:...")

second of all i think your problem is 'div' but im not to sur sorry
JamesXm




PostPosted: Sat Jun 24, 2006 1:18 pm   Post subject: (No subject)

Thank you. I have it working now. Cool
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  [ 4 Posts ]
Jump to:   


Style:  
Search: