Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Ruby- Help converting 4 digit year input into 2 digit output

So far I have.

puts "Enter year:"
year = gets.chomp.to_i
res = year %2 100
puts "Welcome to '#{year}"

Where am I going wrong?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Well, you’ll have to update your code sample a little bit, try this:

 puts "Enter year:"
 year = gets.chomp.to_i  # 4 digits year like 2022
 res = year % 100 # 2 digits year like 22
 puts "Welcome to '#{res}"
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading