Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Passing a variable

Reply
Thread Tools

Passing a variable

 
 
flebber
Guest
Posts: n/a
 
      11-15-2010
I recently discussed in this group the basic starting of a project. I
am getting a little confused at passing a variable between a
calculation.

I am learning so can take some feedback and criticism the part of the
code I am referring to is Scenario 1. I am trying to ensure that the
calcualted value of x is never greater than 1.0. So I am aiming to
determine the value of x for the second calc if the result of the
first calculation produces a valid result.

r = 5.0
p = 10.0
per = 190.0
max_x = 0.8

x = 0.05
const = r*100 # simplified without X
x += 0.05 while (x*const < per) && (x <= max_x)
puts x <= max_x ? "#{x*100.0}%" : "no answer"

Bank = $500.00 # later to be a running total calculated

def ROIcalc
const = r*100 # simplified without X
x += 0.05 while (x*const < per) && (x <= max_x)
puts x <= max_x ? "#{x*100.0}%" : "no answer"
end

def pool
if Bank > 200 then Bank * 0.05
Else $10.00
end

# here in case I need it
def round
return floor(self+0.5) if self > 0.0
return ceil(self-0.5) if self < 0.0
return 0.0
end

# Scenario 1
# simple 2 option scenario where the max allocation is to option a
a = ROIcalc(per = 190, max_x = 0.8, puts "What ratio of return do you
expect?" r = gets.chomp, pool)
If for x in a < 0.6 then x in a = 0.6 & for x in b = 0.4
elseif x > 0.8 then puts " This option is invalid you exceed
allocation" # take user somewhere
# Take user to choose another option
else for x in b = 1.0 - x
b = ROIcalc(per = 200, max_x = 0.4, r = 12.00, pool)
 
Reply With Quote
 
 
 
 
flebber
Guest
Posts: n/a
 
      11-16-2010
On Nov 15, 11:40*pm, flebber <flebber.c...@gmail.com> wrote:
> I recently discussed in this group the basic starting of a project. I
> am getting a little confused at passing a variable between a
> calculation.
>
> I am learning so can take some feedback and criticism the part of the
> code I am referring to is Scenario 1. I am trying to ensure that the
> calcualted value of x is never greater than 1.0. So I am aiming to
> determine the value of x for the second calc if the result of the
> first calculation produces a valid result.
>
> r = 5.0
> p = 10.0
> per = 190.0
> max_x = 0.8
>
> x = 0.05
> const = r*100 # simplified without X
> x += 0.05 while (x*const < per) && (x <= max_x)
> puts x <= max_x ? "#{x*100.0}%" : "no answer"
>
> Bank = $500.00 # later to be a running total calculated
>
> def ROIcalc
> const = r*100 # simplified without X
> x += 0.05 while (x*const < per) && (x <= max_x)
> puts x <= max_x ? "#{x*100.0}%" : "no answer"
> end
>
> def pool
> if Bank > 200 then Bank * 0.05
> Else $10.00
> end
>
> # here in case I need it
> def round
> * return floor(self+0.5) if self > 0.0
> * return ceil(self-0.5) *if self < 0.0
> * return 0.0
> end
>
> # Scenario 1
> # simple 2 option scenario where the max allocation is to option a
> a = ROIcalc(per = 190, max_x = 0.8, puts "What ratio of return do you
> expect?" r = gets.chomp, pool)
> * * * * If for x in a < 0.6 then x in a = 0.6 & for x in b = 0.4
> * * * * * * * * elseif x > 0.8 then puts " This option isinvalid you exceed
> allocation" # take user somewhere
> * * * * * * * * # Take user to choose another option
> * * * * * * * * else for x in b = 1.0 - x
> * * * * b = ROIcalc(per = 200, max_x = 0.4, r = 12.00, pool)


totally changed
 
Reply With Quote
 
 
 
 
flebber
Guest
Posts: n/a
 
      11-16-2010
On Nov 15, 11:40*pm, flebber <flebber.c...@gmail.com> wrote:
> I recently discussed in this group the basic starting of a project. I
> am getting a little confused at passing a variable between a
> calculation.
>
> I am learning so can take some feedback and criticism the part of the
> code I am referring to is Scenario 1. I am trying to ensure that the
> calcualted value of x is never greater than 1.0. So I am aiming to
> determine the value of x for the second calc if the result of the
> first calculation produces a valid result.
>
> r = 5.0
> p = 10.0
> per = 190.0
> max_x = 0.8
>
> x = 0.05
> const = r*100 # simplified without X
> x += 0.05 while (x*const < per) && (x <= max_x)
> puts x <= max_x ? "#{x*100.0}%" : "no answer"
>
> Bank = $500.00 # later to be a running total calculated
>
> def ROIcalc
> const = r*100 # simplified without X
> x += 0.05 while (x*const < per) && (x <= max_x)
> puts x <= max_x ? "#{x*100.0}%" : "no answer"
> end
>
> def pool
> if Bank > 200 then Bank * 0.05
> Else $10.00
> end
>
> # here in case I need it
> def round
> * return floor(self+0.5) if self > 0.0
> * return ceil(self-0.5) *if self < 0.0
> * return 0.0
> end
>
> # Scenario 1
> # simple 2 option scenario where the max allocation is to option a
> a = ROIcalc(per = 190, max_x = 0.8, puts "What ratio of return do you
> expect?" r = gets.chomp, pool)
> * * * * If for x in a < 0.6 then x in a = 0.6 & for x in b = 0.4
> * * * * * * * * elseif x > 0.8 then puts " This option isinvalid you exceed
> allocation" # take user somewhere
> * * * * * * * * # Take user to choose another option
> * * * * * * * * else for x in b = 1.0 - x
> * * * * b = ROIcalc(per = 200, max_x = 0.4, r = 12.00, pool)


totally changed the way I was going about it.

Can this be simplified any further?

# Bank = A running total
def pool
if Bank > 200 then Bank * 0.05
Else $10.00
end

def ROIcalc2
((xunits * max_return)/pool)*100 > Per
end

# scenario 1
xunits = (0.6)step(0.8, 0.05)
Per = 190
puts "What ratio of return do you expect?"
gets.chomp
ROI = (gets.chomp).to_f
max_return = pool * ROI
when xunits in ROIcalc2(xunits, max_return, pool, Per) is true then
Xunits_2 = 1.0 - xunits
puts "xunits equals " + xunits + " xunits2 equals " + Xunits_2
else
puts " This is am invalid option please choose another option "
end
 
Reply With Quote
 
Brian Candler
Guest
Posts: n/a
 
      11-18-2010
Sayth Renshaw wrote in post #961804:
> # Bank = A running total
> def pool
> if Bank > 200 then Bank * 0.05
> Else $10.00
> end
>
> def ROIcalc2
> ((xunits * max_return)/pool)*100 > Per
> end
>
> # scenario 1
> xunits = (0.6)step(0.8, 0.05)
> Per = 190
> puts "What ratio of return do you expect?"
> gets.chomp
> ROI = (gets.chomp).to_f
> max_return = pool * ROI
> when xunits in ROIcalc2(xunits, max_return, pool, Per) is true then
> Xunits_2 = 1.0 - xunits
> puts "xunits equals " + xunits + " xunits2 equals " + Xunits_2
> else
> puts " This is am invalid option please choose another option "
> end


What language is this in? Did you try running it?

Getting your code to work is arguably more important than style

--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
passing copy of a pointer to a variable vs passing the copy pereges C Programming 7 06-01-2008 02:36 PM
Passing a variable value from Javascript to asp.net server variable shil ASP .Net 2 01-02-2007 09:33 PM
passing data from javascript variable to asp variable. Steve Cosh ASP General 1 11-18-2005 04:15 AM
passing javascript variable into asp variable using vbscript Jonas Daunoravicius Javascript 5 07-17-2003 04:54 AM
passing javascript variable into asp variable using vbscript Jonas Daunoravicius ASP General 5 07-17-2003 04:54 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57