Question Help with mod function

mosawa

New member
Joined
Sep 26, 2013
Messages
2
Programming Experience
Beginner
I have an assignment to do ,, I must use mod function but i couldn't solve it

pls i need ur help on the codes


of firewood in bags of different sizes to the public through various retail
outlets. The sizes available are:
Bag size 1 kg 2 kg 5 kg
Bag price $3.80 $6.30 $10.50

The company provides each retail outlet with a program that will calculate the
number and combination of bags required to achieve a required kilogram
weight.
The basis of the calculation is to select a combination of bags that will
minimise the customer's costs. You are required to create the system
using Visual Basic, with all the requirements above. You are allowed to
make changes to the layout of the interface below

Capture.JPG

 
Mod operator is the complement of integer division (using \ operator). While integer division returns only the whole number and discards any fractional part, Mod operator returns the remainder after such division.

Lets say requirement is 8kg: 8 \ 5 =1 and 8 Mod 5 =3. This means you can supply one 5kg unit and have to supply the remainder 3kg by other means. 8-(1*5) =3 is a different calculation to find same remainder. Continue the calculation for the smaller units available until you have fulfilled the total requirement.
 
Mod operator is the complement of integer division (using \ operator). While integer division returns only the whole number and discards any fractional part, Mod operator returns the remainder after such division.

Lets say requirement is 8kg: 8 \ 5 =1 and 8 Mod 5 =3. This means you can supply one 5kg unit and have to supply the remainder 3kg by other means. 8-(1*5) =3 is a different calculation to find same remainder. Continue the calculation for the smaller units available until you have fulfilled the total requirement.


sorry but im still stuck in the codes

this is my codes so far

Private Sub cmdCalculate_Click(sender As Object, e As System.EventArgs) Handles cmdCalculate.Click
'Declare
Dim Quantity As Single
Dim total As Single
Dim cost1kg As Single
Dim cost2kg As Single
Dim cost5kg As Single
Dim num1kg As Integer
Dim num2kg As Integer
Dim num5kg As Integer
Const price5kg As Single = 10.5
Const price2kg As Single = 6.3
Const price1kg As Single = 3.8


'Input
Quantity = Val(txtQuantity.Text)


'Process


num5kg = Quantity \ 5
lbl5kgnum.Text = num5kg


I dont know how to continue from here, pls help me
 
Like so many beginners, you're trying to write the code before you even know what the code is supposed to do. Is it any wonder that you can't write it then? Start by working out the logic, which has nothing whatsoever to do with code so is not even a programming problem. Pick up a pen and paper and write it down. You should be able to write out a set of steps that you can then hand to someone with no prior knowledge of the problem and, if they follow those steps, they should be able to solve the problem manually, e.g. with pen and paper.

Only once you have that clear logic should you even consider writing any code. At any point you can compare your code to your written logic to determine that they do indeed match up. Anything in the written logic that has no equivalent in the code means you need more code. Anything in the code that doesn't relate specifically to something in the written logic is superfluous. If you haven't done that then you haven't really tried all you can to solve the problem. I suggest that you do that and then, if you still have issues, you can show us the logic that you have already devised that you are having trouble implementing in code. If you don't have that logic then why would you expect code to magic into existence?
 
Back
Top