Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Sun 19 May 2013, 02:59
All times are UTC - 4
 Forum index » Off-Topic Area » Programming
A Bacon programming question.
Post new topic   Reply to topic View previous topic :: View next topic
Page 1 of 1 [5 Posts]  
Author Message
tony

Joined: 14 Jan 2006
Posts: 265
Location: Montreal.ca

PostPosted: 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
View user's profile Send private message 
L18L

Joined: 19 Jun 2010
Posts: 1696
Location: Burghaslach, Germany

PostPosted: 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
View user's profile Send private message 
tony

Joined: 14 Jan 2006
Posts: 265
Location: Montreal.ca

PostPosted: 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
View user's profile Send private message 
L18L

Joined: 19 Jun 2010
Posts: 1696
Location: Burghaslach, Germany

PostPosted: 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

Smile
Back to top
View user's profile Send private message 
tony

Joined: 14 Jan 2006
Posts: 265
Location: Montreal.ca

PostPosted: 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
View user's profile Send private message 
Display posts from previous:   Sort by:   
Page 1 of 1 [5 Posts]  
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » Off-Topic Area » Programming
Jump to:  

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
[ Time: 0.0525s ][ Queries: 11 (0.0185s) ][ GZIP on ]