Skip to content

Instantly share code, notes, and snippets.

@ChantalDemissie
Created January 28, 2019 08:20
Show Gist options
  • Save ChantalDemissie/e270acebc69d89833ad37c7f06fc8f73 to your computer and use it in GitHub Desktop.
Save ChantalDemissie/e270acebc69d89833ad37c7f06fc8f73 to your computer and use it in GitHub Desktop.
num_students = 5
student_data = Array.new(num_students)
puts "Please enter the names of 5 students when prompted."
num_students.times do |i|
puts "First Name: "
first = gets.chomp
puts "Last Name: "
last = gets.chomp
full_name = first.strip + " " + last.strip
puts "Full Name is: " + full_name.upcase
student_data_hash = Hash.new
student_data_hash[:name] = full_name.upcase
random_id = Random.new.rand(111111..999999)
student_data_hash[:id] = random_id
first_initial = first[0]
id_digits = random_id.digits
last_three_of_id = ""
3.times do |j|
letter_id = 2-j
last_three_of_id += id_digits[letter_id].to_s
end
email = first_initial + last + last_three_of_id + "@adadevelopersacademy.org"
student_data_hash[:email] = email
student_data[i] = student_data_hash
end
puts "Here is each student's information..."
num_students.times do |i|
puts "Full Name: " + student_data[i][:name]
puts "Student ID: " + student_data[i][:id].to_s
puts "E-mail Address: " + student_data[i][:email]
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment