Display Decimal Places

New to FreeBASIC? Post your questions here.
Post Reply
baserunner0723
Posts: 1
Joined: Aug 14, 2018 21:41

Display Decimal Places

Post by baserunner0723 »

I know a little about basic but i can't figure out how to display decimals.

Code: Select all

dim fr as integer 
dim fe as integer 
dim ama as integer
dim ima as integer
dim eff as integer
dim choice as integer

print "What Simple Machine do you want to calculate MA for?"
print "1. Inclined Plane"
input "Choice: " , choice 

if choice = 1 then
    dim L as integer
    dim H as integer
    input "What is the Length of the ramp? " , L
    input "What is the Height of the ramp? " , H
    input "What is Fr? " , fr
    input "What is Fe? " , fe
    ima=L/H
    ama=fr/fe
    eff=(ama/ima)*100
    cls 
    print "Results"
    print "IMA: " ; ima ; ":1"
    print "AMA: " ; ama ; ":1"
    print "Efficiency: " ; eff ; "%"
    sleep
endif 
sleep
MrSwiss
Posts: 3910
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: Display Decimal Places

Post by MrSwiss »

Hi,

welcome to the forum.

Integers are "whole numbers" only, if you want decimals you'll have to use floats:
Single (precision) 32 bit, or Double (precision) 64 bit.
See: Wikipedia for detailed info.

Code: Select all

dim as single fr, fe, ama, ima, eff, choice

print "What Simple Machine do you want to calculate MA for?"
print "1. Inclined Plane"
input "Choice: " , choice

if choice = 1 then
    dim L as integer
    dim H as integer
    input "What is the Length of the ramp? " , L
    input "What is the Height of the ramp? " , H
    input "What is Fr? " , fr
    input "What is Fe? " , fe
    ima=L/H
    ama=fr/fe
    eff=(ama/ima)*100
    cls
    print "Results"
    print "IMA: " ; ima ; ":1"
    print "AMA: " ; ama ; ":1"
    print "Efficiency: " ; eff ; "%"
    sleep
endif
sleep
paul doe
Moderator
Posts: 1733
Joined: Jul 25, 2017 17:22
Location: Argentina

Re: Display Decimal Places

Post by paul doe »

Hi, baserunner0723. Welcome to the forum.

Be sure to also check the Documentation forum. You'll find invaluable information there, including a PDF manual to help you get started with FreeBasic.

Cheers!
Post Reply