Where did I go wrong? The goal is to find the number and combination of coins weighing 5.78 grams, 5.05 grams and 4.2 grams to give as close as possible or exactly 200 grams. It is QBASIC. Is there such a thing on the internet?
Code:
din = 0
pet = 0
dva = 0
aktuelno = 250
for a = 0 to 48
pet = din
for b = 0 to 41 - a
pet = dva + din
for c = 1 to 36 - b - a
pet = pet + 5.78
tekuce = ABS(200 - pet)
if tekuce < aktuelno
aktuelno = tekuce
pamtimdin = a
pamtimdva = b
pamtimpet = c
end if
next c
dva = dva + 5.05
next b
dinar = dinar + 4.2
next a
print aktuelno
print "pet: " ; pamtimpet
print "dva: " ; pamtimdva
print "din: " ; pamtimdin
Last edited: