The time now is Sun 19 May 2013, 02:59
All times are UTC - 4 |
| Author |
Message |
tony
Joined: 14 Jan 2006 Posts: 265 Location: Montreal.ca
|
Posted: Sat 14 Apr 2012, 04:55 Post subject:
A Bacon programming question. Subject description: Simple inputting of data. |
|
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.
|
|
Back to top
|
|
 |
L18L
Joined: 19 Jun 2010 Posts: 1696 Location: Burghaslach, Germany
|
Posted: Sat 14 Apr 2012, 05:58 Post subject:
Re: A Bacon programming question. Subject description: Simple inputting of data. |
|
| 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: | # echo "3.14*2" | bc -l
6.28
# |
|
|
Back to top
|
|
 |
tony
Joined: 14 Jan 2006 Posts: 265 Location: Montreal.ca
|
Posted: Sat 14 Apr 2012, 15:51 Post subject:
|
|
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.
|
|
Back to top
|
|
 |
L18L
Joined: 19 Jun 2010 Posts: 1696 Location: Burghaslach, Germany
|
Posted: Sun 15 Apr 2012, 09:57 Post subject:
|
|
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
|
|
Back to top
|
|
 |
tony
Joined: 14 Jan 2006 Posts: 265 Location: Montreal.ca
|
Posted: Sun 15 Apr 2012, 14:11 Post subject:
Subject description: Solved. |
|
Hi L18L,
many thanks, that Bacon code you posted works and is exactly what I required.
Regards Tony.
|
|
Back to top
|
|
 |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|