A combination of coins to give as close or exact as possible to 200 grams

Joined
Mar 17, 2025
Messages
1
Reaction score
0
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:

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,302
Messages
2,571,545
Members
48,344
Latest member
Darcy80V04
Top