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.
A Bacon programming question.
- L18L
- Posts: 3479
- Joined: Sat 19 Jun 2010, 18:56
- Location: www.eussenheim.de/
Re: A Bacon programming question.
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.....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.
simplest tool for floating point math is /usr/bin/bc
ex:
Code: Select all
# echo "3.14*2" | bc -l
6.28
#
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.
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.
- L18L
- Posts: 3479
- Joined: Sat 19 Jun 2010, 18:56
- Location: www.eussenheim.de/
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
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