0

(sorry my bad english) I am a beginner and in an exercise the one who run the program must insert his birth date and the program must says if today is his birthday or not.
In C to do this I can do (I jump a part of code):

printf("Insert your birth day (DD MM YYYY): ");
scanf("%d%d%d",&db,&mb,&yb);
printf("Insert the current day (DD MM YYYY): ");
scanf("%d%d%d",&dc,&mc,&yc);

(db = day birth; mb = month birth; dc = day current etc.)
And the rest of the code is not important for what I want to ask.
So, and in Ruby? I must use gets each time for any of DD, MM, and YYYY separately?
There will be 6 gets, so many lines of code, is there any way to use
just 1 time gets for all the date like in C? Or some other way to write less code? Thanks!

Edited by peter_budo: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks)

3
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by xml_looser
2
require 'time'
puts "enter your birth date (mm/dd/yyy):"
birth_date = Time.parse(gets.chomp)
right_now = DateTime::now()
puts "today is your birthday" if (birth_date.month == right_now.month && birth_date.day == right_now.day)

Edited by peter_budo: Keep It Organized -For easy readability, always wrap programming code within posts in [code] (code blocks)

0
STDOUT.print "input your birthday (DD.MM.YYYY)"
STDOUT.flush
b=gets.chomp
STDOUT.print "input today (DD.MM.YYYY)"
STDOUT.flush
u=gets.chomp
print u,"  ",b
if u==b
STDOUT.print "EGQUAL"
else
STDOUT.print "NOT EGQUAL" 
end
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.