Created
January 25, 2019 02:20
-
-
Save ChantalDemissie/6f1c11907ad5caaadc89015023620f81 to your computer and use it in GitHub Desktop.
student account generator array
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Assignment: Student Account Generator | |
num_students = 5 | |
student_names = Array.new(num_students) | |
student_ids = Array.new(num_students) | |
student_emails = Array.new(num_students) | |
puts "Please enter the names of 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_names[i] = full_name.upcase | |
end | |
num_students.times do |i| | |
random_id = Random.new.rand(111111..999999) | |
student_ids[i] = random_id | |
puts student_ids[i] | |
end | |
num_students.times do |i| | |
puts student_names[i] | |
puts student_ids[i] | |
first_initial = student_names[i][0] | |
puts "first initial: " + first_initial | |
names = student_names[i].split(" ") | |
last_name = names[1] | |
puts "last name: " + last_name | |
id_digits = student_ids[i].digits | |
puts "length: " + id_digits.length.to_s | |
last_three_of_id = id_digits[-3..-1].join("") | |
email = first_initial + last_name + last_three_of_id + | |
"@adadevelopersacademy.org" | |
student_emails[i] = email | |
puts "last 3: " + last_three_of_id | |
puts "e-mail: " + email | |
end | |
puts "Here is each student's information..." | |
num_students.times do |i| | |
puts "Full Name: " + student_names[i] | |
puts "Student ID: " + student_ids[i].to_s | |
puts "E-mail Address: " + student_emails[i] | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Good work! 👍
Out of curiosity: what are the pros and cons of organizing the code to have 3 loops back to back (starting on lines 7, 16 and 21), versus making it part of a single loop?