How to do computation in Liberty Basic

  • Thread starter Nothing000
  • Start date
  • Tags
    Computation
In summary, the speaker is trying to convert a value in inches to feet in a simple program using Liberty Basic. They plan to divide the inches by 12 and then multiply the decimal portion by 12 to get the value in feet and inches. They ask for help on how to multiply only the numbers after the decimal point and if Liberty Basic has a function for this. The expert suggests using the Int() function and subtracting the integer portion to get the decimal portion. The speaker asks how to do this for a variable number and the expert suggests using the backslash character for integer division.
  • #1
Nothing000
403
0
I am trying to write a very simple program in Liberty Basic. The last step in the program gives me a answer in inches, and I want to convert it to feet. So I figured I would simply divide the answer in inches by 12, then multiply ONLY the decimal value by 12, and then I would have the value in feet and inches.
So how do I multiply by only the numbers after the decimal point?
 
Technology news on Phys.org
  • #2
When I said that I will have the answer in feet AND inches, I mean that it would say x feet and z inches. Just like someone would say if if they were talking about a length in feet that is not exactly x feet.
 
  • #3
Does Liberty Basic have an INT() or FLOOR() function?
 
  • #4
Yes, it does have an Int() function.
 
  • #5
Int() should give you the integer portion. If you need the decimal portion just subtract your floating point number by the integer portion.

14.22-14 = .22
 
  • #6
But what if the number is a variable. Like in your example, sometimes the answer comes out to 14.22, but in some situations it would be 144.22, or a number other than 14.22. So how can I strip away the whole number and just leave the decimal portion for me to do calculations with. And how can I do that in a general way. I am not sure if I am being very clear, tell me if I am not. I am very new at this. By the way, thanks for the help. You are definitely pointing me in the right direction.
 
  • #7
Like I want to tell it to just leave 0.xx from the answer that it is giving me now so I can multiply only this decimal portion of the number by a fixed number (12).
 
  • #8
totalinches = 39.5
onefoot = 12
feet = int(totalinches/onefoot)
inches = totalinches - (feet*onefoot)

I think this will do what you want.

If your language uses the backslash character for integer division, (returns only the whole portion of a division) you could write the feet caclulation as...
feet = totalinches\onefoot
 
Last edited:
  • #9
Thanks BobK. That worked perfectly.
 

1. How do I perform basic arithmetic operations in Liberty Basic?

In Liberty Basic, you can use the symbols +, -, *, and / to perform addition, subtraction, multiplication, and division respectively. For example, to add two variables A and B and store the result in C, you can use the statement "C=A+B".

2. Can I use loops and conditional statements in Liberty Basic?

Yes, Liberty Basic supports the use of loops and conditional statements. You can use the "DO...LOOP" statement for loops and "IF...THEN" statement for conditional statements. These allow you to execute a block of code repeatedly or conditionally based on certain criteria.

3. How can I accept user input in Liberty Basic?

You can use the "INPUT" statement to prompt the user for input and store it in a variable. For example, "INPUT "Enter your name: "; Name$" will display the message and store the user's input in the variable Name$.

4. Is there a way to create and use functions in Liberty Basic?

Yes, Liberty Basic allows you to define and call your own functions. You can use the "FUNCTION...END FUNCTION" statement to define a function and the "CALL" statement to execute it. You can also pass parameters to functions and return values from them.

5. How do I handle errors and exceptions in Liberty Basic?

Liberty Basic has built-in error handling functionality. You can use the "ON ERROR GOTO" statement to specify a label or line number to jump to when an error occurs. You can also use the "ERR" function to retrieve the error number and "ERL" function to retrieve the line number where the error occurred.

Similar threads

  • Programming and Computer Science
Replies
29
Views
3K
Replies
10
Views
999
  • Programming and Computer Science
Replies
27
Views
2K
  • Sticky
  • Programming and Computer Science
Replies
13
Views
4K
  • Engineering and Comp Sci Homework Help
Replies
4
Views
897
  • Programming and Computer Science
Replies
3
Views
1K
  • Programming and Computer Science
Replies
32
Views
3K
  • Programming and Computer Science
2
Replies
37
Views
2K
  • Programming and Computer Science
Replies
1
Views
931
  • Programming and Computer Science
Replies
11
Views
769
Back
Top