A simple Result Programme,Ruby

task:take input and check the value some number range and tell us the result.

technique used of ruby

-case statement (in other language is switch statement)

-range ex:(1..5)

example code: result.rb

——————————————–

puts(“Enter Your Result”)
score=gets
result = case score.to_f
when 0..40 then “Fail”
when 41..60  then “Pass”
when 61..70 then “Pass with Merit”
when 71..100   then “Pass with Distinction”
else “Invalid Score”
end

puts result

———————————

you can run the programme here and see the output live

built in function use

-puts[ print on screen,string type ]

-gets[get input as string]

-to_f [ convert to float ]

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s