Skip to content

Instantly share code, notes, and snippets.

@dirkkelly
Last active August 29, 2015 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dirkkelly/d961975443a40a8b4469 to your computer and use it in GitHub Desktop.
Save dirkkelly/d961975443a40a8b4469 to your computer and use it in GitHub Desktop.
A CodeNow refresher project.

Grade Calculator

Introduction

A refresher program aimed at understanding.

  • Iteratives
  • Conditionals
  • String Interpolation

Psuedo Code

# Ask user for name
'What is your name?'
=> John
# Ask user for grade
'Are you a Freshman, Sophomore, Junior or Senior?'
=> Sophmore
# Tell user what year they are in
'Hi John, you are in year 10'
# Ask user to go again
'Would you like to try again? y/n'
=> y

Extensions

  • Ignore case on any strings
  • Only match on first character of try again
  • Validate the user selection
begin
puts 'What is your name?'
name = gets.chomp
puts 'Are you a Freshman, Sophomore, Junior or Senior?'
grade = gets.chomp.downcase
if grade == 'freshman'
year = 9
elsif grade == 'sophmore'
year = 10
elsif grade == 'junior'
year = 11
elsif grade == 'senior'
year = 12
else
puts 'Not a valid choice'
exit
end
puts "Hi #{name}, you are in year #{year}"
puts 'Would you like to try again? y/n'
continue = gets.chomp.downcase[0]
end while continue == 'y'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment