Reputation: 3
I understand how to open and then print the content of the file. I would like to understand how to ask a second question on a new line after the txt file has been printed.
The code below prints the output of the text file, then on the same line, asks "Type the file name again:"
filename = ARGV.first
txt = open(filename)
puts "Here's your file #{filename}:"
print txt.read
print "Type the filename again: "
file_again = $stdin.gets.chomp
txt_again = open(file_again)
print txt_again.read
I would like this question to be printed on a new line after the txt file has been read.
Upvotes: 0
Views: 31
Reputation: 56
You should use puts and not print. The difference is that puts add a new line at the end of the output.
filename = ARGV.first
txt = open(filename)
puts "Here's your file #{filename}:"
puts txt.read // Changed Line
print "Type the filename again: "
file_again = $stdin.gets.chomp
txt_again = open(file_again)
puts txt_again.read //Changed Line
Upvotes: 1