Begginer needs help

Hi i’m in a programming a class and i’m doing an assignment i’ve gotten
it to work but one of the entries is messed up it takes the place of a
diffrent one

Here’s the code

require ‘gtk2’

window = Gtk::Window.new
window.border_width = 10
window.title = “Future Value Investment Calculator”
window.resize(450,200)

convertButton = Gtk::Button.new(“Convert”)
closeButton = Gtk::Button.new(“Close”)
oink = Gtk::Image.new(Gdk::Pixbuf.new(“piggybank.gif”, 150, 200))
promptLabel = Gtk::Label.new(“Enter amount invested in U.S Dollars:”)
tempEntry = Gtk::Entry.new
promptLabel2 = Gtk::Label.new(“Enter Rate of return as a decimal(e.g.
enter 8% as .08):”)
tempEntry2 = Gtk::Entry.new
promptLabel3 = Gtk::Label.new(“Enter number of years the money will be
invested:”)
tempEntry3 = Gtk::Entry.new
resultLabel = Gtk::Label.new("")

vbox1 = Gtk::VBox.new(false, 0)
hbox1 = Gtk::HBox.new(false, 0)
hbox2 = Gtk::HBox.new(false, 0)

hbox1.pack_start(convertButton, true, false)
hbox1.pack_start(closeButton, true, false)

vbox1.pack_start(promptLabel, true, true)
vbox1.pack_start(tempEntry, true, true)
vbox1.pack_start(promptLabel2, true, true)
vbox1.pack_start(tempEntry2, true, true)
vbox1.pack_start(promptLabel3, true, true)
vbox1.pack_start(tempEntry3, true, true)
vbox1.pack_start(resultLabel, true, true)
vbox1.pack_start(hbox1, true, true)

hbox2.pack_start(vbox1, true, true)
hbox2.pack_start(oink, true, true)

window.add(hbox2)
window.show_all

convertButton.signal_connect(“clicked”) {

dollars = tempEntry.text.to_f

rate = tempEntry.text.to_f

time = tempEntry.text.to_i

fv = dollars*(1+rate)**time

output= " In " + time.to_s + " years your investment will be worth " +
fv.to_s

resultLabel.set_label( output )
}

closeButton.signal_connect(“clicked”) {
Gtk.main_quit
}

window.signal_connect(“destroy”) {
Gtk.main_quit
}

Gtk.main

if u could help i would really appreciate it

Hi,

On 26.09.2010 02:36, Jake Alucard wrote:

convertButton.signal_connect(“clicked”) {

dollars = tempEntry.text.to_f

rate = tempEntry.text.to_f

time = tempEntry.text.to_i

Look carefully which gtk widgets you access. You always access
“tempEntry” but you named the others “tempEntry2” and “tempEntry3”.

Lesson you should learn here: use distinctive naming :wink:

  • Markus

thank you so much :smiley: