Skip to content

Commit

Permalink
adding 29, 30
Browse files Browse the repository at this point in the history
  • Loading branch information
lancelakey committed Dec 27, 2011
1 parent 855cf13 commit 1c5290a
Show file tree
Hide file tree
Showing 3 changed files with 109 additions and 0 deletions.
39 changes: 39 additions & 0 deletions ex29.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/usr/bin/env ruby

people = 20
cats = 30
dogs = 15

if people < cats
puts "Too many cats! The world is doomed!"
end

if people > cats
puts "Not many cats! The world is saved!"
end

if people < dogs
puts "The world is drooled on!"
end

if people > dogs
puts "The world is dry!"
end

dogs += 5

if people >= dogs
puts "People are greater than or equal to dogs."
end

if people <= dogs
puts "People are less than or equal to dogs."
end

if people == dogs
puts "People are dogs."
end

# 1. What do you think the if does to the code under it?
# I think if waits to do anything with the code inside depending on the result of the if
#
33 changes: 33 additions & 0 deletions ex30.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/env ruby

people = 30
cars = 40
buses = 15

if cars > people
puts "We should take the cars."
elsif cars < people
puts "We should not take the cars."
else
puts "We can't decide."
end

if buses > cars
puts "That's too many buses."
elsif buses < cars
puts "Maybe we could take the buses."
else
puts "We still can't decide."
end

if people > buses
puts "Alright, let's just take the buses."
else
puts "Fine, lets stay home then."
end


# Extra Credit:
# 1. Try to guess what elsif and else are doing.
# try the if, if that doesn't work, try the elsif, if none of those work, do the else
#
37 changes: 37 additions & 0 deletions ex30_3.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/usr/bin/env ruby

# Extra Credit:
# 3. Try some more complex boolean expressions like cars > people and buses < cars. Above each line write an English description of what the line does.

boys = 5
girls = 5
fathers = 10
mothers = 10

if boys and girls <= fathers
puts "Boys and girls is <= fathers"
end

if boys and girls < fathers and mothers
puts "Boys and girls is less than fathers and mothers"
end

if not (boys > fathers) and not (girls > mothers)
puts "Scouts!"
else
puts "No scouts!"
end

if boys and girls and fathers and mothers < 50
puts "Everyone is less than 50"
else
puts "Everyone is more than 50"
end

if boys == girls and fathers == mothers
puts "Boys == Girls and Fathers == Mothers"
else
puts "It don't all equal"
end


0 comments on commit 1c5290a

Please sign in to comment.