sdem9
1
I have to write some code (duh) and I will have a menu that says
puts “Welcome To The Baseball Calculator”
puts “1. Show Major League winners”
puts “2. Show number of wins for a team”
puts "3. Exit "
choice = gets.chomp.to_i
if choice == 1
end
thats all I have so far…
I have a text file “winners” and a text file “teams”
how do I open/read those
Maniac
2
Hello @sdem9,
Would be really helpful if you post your code directly in your topic.
1 Like
sdem9
3
class SportsFiles
def initialize (teams)
@Teams = “teams.txt”
end
def read_file(teams)
file = File.open(“teams.txt”, “r”)
end
puts “Welcome To The Baseball Calculator”
puts “1. Show Major League winners”
puts “2. Show number of wins for a team”
puts "3. Exit "
choice = gets.chomp.to_i
if choice == 1
puts
end
end
Maniac
4
Thanks @sdem9!
If you would like to read the file and to show each line:
teams = File.open('teams.txt', 'r')
teams.each do |team|
p team
end
sdem9
5
Thank you so much @Maniac !!
sdem9
7
im not sure where im suppose to place in my code…
sdem9
8
nvm I got it lol thanks for all the help