Display Decimal Places

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

Display Decimal Places

Postby baserunner0723 » Aug 14, 2018 21:47

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: 2735
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: Display Decimal Places

Postby MrSwiss » Aug 16, 2018 15:51

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
Posts: 722
Joined: Jul 25, 2017 17:22
Location: Argentina

Re: Display Decimal Places

Postby paul doe » Aug 16, 2018 19:31

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!

Return to “Beginners”

Who is online

Users browsing this forum: No registered users and 1 guest