Advertisement
daixso

how to ruby plx

Oct 1st, 2012
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 1.85 KB | None | 0 0
  1. #Author:Zachary Williams
  2. #Date: 10-1-12 19:57
  3. #Chain of Command ROTC study guide
  4.  
  5. #titles array
  6. t=["The President of the United States","Vice President of the United States","Secretary of State","Secretary of Defense",
  7.     "Secretary of the Navy","Chairman, Joint Chiefs of Staff","Chief of Naval Operations","Commandant of the Marine Corps",
  8.     "Master Chief Petty Officer of the Navy","Sergeant Major of the Marine Corps","Commander of Naval Education and Training Command",
  9.     "Commander of Naval Service Training Command","NJROTC Area 12 Commander","Senior Naval Science Instructor","Naval Science Instructor"]
  10. #names array
  11. n=["The Honorable Barack Obama","The Honorable Joseph Biden","The Honorable Hillary Clinton","The Honorable Leon Panetta",
  12.     "The Honorable Ray Mabus","General Martin Dempsey","Admiral Jonathan Greenert","General James Amos",
  13.     "Master Chief Petty Officer Michael Stevens","Sergeant Major Michael Barrett","Rear Admiral Donald Quin","Rear Admiral David Steindl",
  14.     "Commander Rusty Hibbard","Captain William Wilkerson","First Sergeant Lorenzo Cox"]
  15. #used array
  16. u=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
  17. #score, set to 0 at beginning of each play through
  18. score=0
  19.  
  20. def PickPerson
  21.     getPerson=rand(15)
  22.     CheckUsed(getPerson)
  23. end
  24.  
  25. def CheckUsed(num)
  26.     picks=0
  27.     if num == 0
  28.         picks=0
  29.         Quiz(num)
  30.     else
  31.         PickPerson
  32.         picks=picks+1
  33.         if picks >= 15
  34.             puts "You have answered all the questions!"
  35.             FinalScore(score)
  36.         end
  37.     end
  38. end
  39.  
  40. def Quiz(num)
  41.     puts "Who is your " + t[num] + "?"
  42.     print "Answer: "
  43.     while tries <= 3
  44.         answer=gets.chomp  
  45.         if answer == n[num]
  46.             puts "Correct! +10 pts"
  47.             QuizScore
  48.         elsif answer == "exit"
  49.             break
  50.         else
  51.             tries=tries+1
  52.         end
  53.     end
  54.        
  55. end
  56.  
  57. def QuizScore
  58.     score=score+1
  59.     PickPerson
  60. end
  61.  
  62. def FinalScore(s)
  63.     finalScore=s*10
  64.     print "Your final score is "
  65.     return finalScore
  66. end
  67.  
  68. PickPerson()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement