Skip to content

Instantly share code, notes, and snippets.

@olistik
Last active August 29, 2015 14:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save olistik/a9c4f56986be9f6675ef to your computer and use it in GitHub Desktop.
Save olistik/a9c4f56986be9f6675ef to your computer and use it in GitHub Desktop.
nome_file = 'quantita_rimasta.txt'
if File.exists?(nome_file)
quantita_rimasta = File.read('quantita_rimasta.txt').to_i
else
quantita_rimasta = 100
File.write(nome_file, quantita_rimasta)
end
prodotto0 = 'cemento'
prezzo0 = 4
continua_ciclo = true
totale = 0
while continua_ciclo
print 'Inserire prodotto da ricercare (scrivi \'totale\' per mostrare il totale e uscire dal programma): '
scelta = gets.chomp
if scelta == 'totale'
continua_ciclo = false
elsif scelta == prodotto0
puts 'cad.: ' + prezzo0.to_s + ' $'
puts 'Quantita disponibile in magazzino: ' + quantita_rimasta.to_s
print 'Inserire quantita richiesta: '
quantita_richiesta = gets.chomp.to_i
totale = totale + (prezzo0 * quantita_richiesta).to_i
puts 'Sub totale: ' + totale.to_s + ' $'
quantita_rimasta = quantita_rimasta - quantita_richiesta
puts 'Quantita rimasta: ' + quantita_rimasta.to_s
else
puts 'Prodotto non presente.'
end
end
puts 'Totale ' + totale.to_s + ' $'
File.write(nome_file, quantita_rimasta)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment