Support Forums

Full Version: Todo List
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Code:
loop = 0
while loop = 1
    puts "1) Add Something"
    puts "2) View List"
    puts "3) Remove Something"
    puts "4) Clear List"
    print "What do you want to do?: "
    choice = gets.chomp
    choice = choice.to_i
    if choice == 2
        array = []
        file = File.open("todo.txt", "r")    
        file.each_with_index do |line,number|
        if number == 0
            print ""    
        else
            puts "#{number}: #{line}"
        end    
        array << line    
        end
        file.close
        print "Press Enter To Continue..."
        continue = gets.chomp
    end
    if choice == 1
        file = File.open("todo.txt", "a")
        print "What do you want to add?: "
        whattoadd = gets.chomp
        file.puts whattoadd
        file.close
    end
    if choice == 3
        array = []
        file = File.open("todo.txt", "r")    
        file.each_with_index do |line,number|
        if number == 0
            print ""    
        else
            puts "#{number}: #{line}"
        end    
        array << line    
        end
        file.close
        print "What do you want to remove?: "
        whattoremove = gets.chomp
        whattoremove = whattoremove.to_i
        array.delete array[whattoremove]
        file = File.open("todo.txt", "w")
        file.puts array.join
        file.close
    end
    if choice == 4
        file = File.open("todo.txt","w")
        file.puts ""
        file.close
    end
end