A Bacon programming question.

For discussions about programming, programming questions/advice, and projects that don't really have anything to do with Puppy.
Post Reply
Message
Author
tony
Posts: 334
Joined: Sat 14 Jan 2006, 10:52
Location: Montreal.ca

A Bacon programming question.

#1 Post by tony »

Hi,

How do I input three floating point numbers without hitting the enter key three times?

Is BaCon the right language to use for simple floating point maths?

Regards Tony.

User avatar
L18L
Posts: 3479
Joined: Sat 19 Jun 2010, 18:56
Location: www.eussenheim.de/

Re: A Bacon programming question.

#2 Post by L18L »

tony wrote:Hi,

How do I input three floating point numbers without hitting the enter key three times?

Is BaCon the right language to use for simple floating point maths?

Regards Tony.
Make a GUI and use the mouse thus you don´t have to hit the enter key. Or separate them by a space, hit the enter key once and use the words.....

simplest tool for floating point math is /usr/bin/bc
ex:

Code: Select all

# echo "3.14*2" | bc -l
6.28
#

tony
Posts: 334
Joined: Sat 14 Jan 2006, 10:52
Location: Montreal.ca

#3 Post by tony »

Hi L18L,

thank you for coming back. Here is my simple Bacon program :-

DECLARE prot,carbs,fat,points TYPE float

INPUT "protein ",prot
INPUT "carbohydrates ",carbs
INPUT "fat ",fat
points = prot/10.94 + carbs/9.17 + fat/3.89
PRINT "points: ",points

I would like to replace the three input statements by a single one liner.

Obviously inputting floating point numbers into say a three by three, or an even larger matrix would be a bit tedious.

My apologies for not being very clear in my first post

Regards Tony.

User avatar
L18L
Posts: 3479
Joined: Sat 19 Jun 2010, 18:56
Location: www.eussenheim.de/

#4 Post by L18L »

Hi Tony,

try this:

DECLARE prot,carbs,fat,points TYPE float

'INPUT "protein ",prot
'INPUT "carbohydrates ",carbs
'INPUT "fat ",fat

INPUT "protein carb fat: ", pcf$
SPLIT pcf$ BY " " TO c$ SIZE num
prot = VAL(c$[0])
carbs = VAL(c$[1])
fat = VAL(c$[2])


points = prot/10.94 + carbs/9.17 + fat/3.89

PRINT "points: ",points

:)

tony
Posts: 334
Joined: Sat 14 Jan 2006, 10:52
Location: Montreal.ca

#5 Post by tony »

Hi L18L,

many thanks, that Bacon code you posted works and is exactly what I required.

Regards Tony.

Post Reply