Computer Science Canada

"round" command help.

Author:  WOIKeller [ Mon Jun 08, 2009 2:10 pm ]
Post subject:  "round" command help.

What is it you are trying to achieve?
I need help using the round command.


What is the problem you are having?
I have made a batting average program for school that includes a form of compiler and database but when the program calculates the batting average of a player I don't want it to store values like 75.6927639498273497947%

Just 76% or if possible 75.7% would do just fine


Describe what you have tried to solve this problem
I tried looking into the round command but the description is limited at best.


Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
Turing:

    put "Enter the player's last name:" ..
    get name
    put ""
    put "Enter their number of at bats:" ..
    get atBats
    put ""
    put "Enter the number of successful hits:" ..
    get hits
    battingAverage := (hits / atBats) * 100
    put ""
    put "If ", name, " has ", hits, " successful hits out of ", atBats, " times at bat."
    put "The batting average of ", name, " is ", battingAverage, "%"
    put ""

    put "would you like to store this info?"
    put "y or n?"
    get store : 1


Please specify what version of Turing you are using
Turring v4.0.5

Author:  BigBear [ Mon Jun 08, 2009 2:21 pm ]
Post subject:  RE:"round" command help.

putting round(battingAverage) will convert it to a int meaning no decimal portion

Author:  WOIKeller [ Mon Jun 08, 2009 2:35 pm ]
Post subject:  RE:"round" command help.

I tried that but I get an error saying "Expression is not a procedure and hance cannot be called"

Author:  BigBear [ Mon Jun 08, 2009 2:41 pm ]
Post subject:  RE:"round" command help.

Which means it is a function and it returns a value so you need to put the value

Author:  WOIKeller [ Tue Jun 09, 2009 7:14 am ]
Post subject:  RE:"round" command help.

Wow!!! That worked like a charm. Thank you ever so much.


: