Sign in to follow this  
Followers 0
Space38

backward counter

12 posts in this topic

#1 ·  Posted (edited)

hi all

i wonder guys if there's way to add something like counter but in backward .

let's say that i have product A=10$ ,B=20$ ,C=30$  and i want to make a price list cost ( + / -)200$ with this products

and i want from script to make the selection of products (A_B_C) and determined the number of each product to make the +/- 200$ list

like this

5 piece of (A) = 10$ * 5 =50$

5 piece of (B ) = 20$ * 5 =100$

2 piece of (C ) = 30$ * 2 =60$

---------------------------------------

                                       210$

thanks in advance

Edited by Space38

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Well it is possible to make a loop go backward, instead of forward, but that isn't really what you want here.

I think what you want is how many times each item can be multiplied so that the total is within a maximum (however much above 200 (which you must define)) and a minimum - (however much below 200 (which you must define)).

That's a bit too much math logic for me to figure out (within +- an undetermined time :) ), but I'm sure someone here will be more help to you.

Good luck with your project, and welcome to the Forum!

Edited by somdcomputerguy

- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

Share this post


Link to post
Share on other sites

Homework?

Well if one was to provide the code written to do this (preferebly written by oneself, which honestly I don't think is going to happen here..), that should be extra credit, ya?


- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Ya, I remember seeing seeing some code here that either will do just that, or would require just a tiny bit of modification. I don't remember what the topic was, or what the code was for, so like you I don't feel like searching for it either.

edit: corrected typo

Edited by somdcomputerguy

- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

Share this post


Link to post
Share on other sites

my laptop is broken right now and i'm using my friend PC i will start coding soon and i will post the code once i finish it

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

 

From what you've posted here, It looks like you're more or less looking for some form of excel calculator. Though I could be mistaken. Here's a example script, With some modification you could get it to do what you're looking for, I think, Possibly with a For Loop;

$A = "Apple"
$B = "Banana"
$C = "Orange"

$A_Quantity = InputBox("Quantity Check", "How many " & $A & "'s do you have?", "", "")
$B_Quantity = InputBox("Quantity Check", "How many " & $B & "'s do you have?", "", "")
$C_Quantity = InputBox("Quantity Check", "How many " & $C & "'s do you have?", "", "")

$A_Result = Number(10 * $A_Quantity)
$B_Result = Number(20 * $B_Quantity)
$C_Result = Number(30 * $C_Quantity)

$Total = Number($A_Result + $B_Result + $C_Result)
If $Total > "200" Then
   MsgBox(0, "Error", "Error: Your Total Exceeds $200", "")
ElseIf $Total <= "200" Then
   MsgBox(0, "Checkout", "" & $A_Quantity & " piece(s) of (" & $A & ") = $10 * " & $A_Quantity & " = $" & $A_Result & "" & @CRLF & "" & $B_Quantity & " piece(s) of (" & $B & ") = $20 * " & $B_Quantity & " = $" & $B_Result & "" & @CRLF & "" & $C_Quantity & " piece(s) of (" & $C & ") = $30 * " & $C_Quantity & " = $" & $C_Result & "" & @CRLF & "" & @CRLF & "Your total is: $" & Number($A_Result + $B_Result + $C_Result) & "")
EndIf

Edit: Added a If statement to check for totals exceeding $200.

Edited by BlackDawn187

Share this post


Link to post
Share on other sites

It's the knapsack problem.


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites

Here is a method that returns one result only.

If all possible combinations are required, like:-

21-A's = 21x$10 = $210, and,

19-A's + 1-B = 19x$10 + $20 = $210, etc.

This would be another interpretation which may or may not be required.

#include <Array.au3>

Local $a[3] = [10, 20, 30]
Local $Target = 210 ; 205
Local $Total = 0
Local $Flag = 0
Local $aAns[UBound($a)][3] = [["A = " & $a[0]],["B = " & $a[1]],["C = " & $a[2]]] ; ,["D = " & $a[3]]]

While $Target <> $Total
    $Flag = 0
    For $i = UBound($a) - 1 To 0 Step -1
        If $Total + $a[$i] <= $Target Then
            $Total += $a[$i]
            $aAns[$i][1] += 1
            $aAns[$i][2] += $a[$i]
            $Flag -= 1
            ;ConsoleWrite($Total & @LF)
        Else
            $Flag += 1
        EndIf
        If $Flag = UBound($a) - 1 Then ; When $Target will never equal $Total
            ExitLoop 2
        EndIf
    Next
WEnd

ReDim $aAns[UBound($aAns) + 1][3]
$aAns[UBound($aAns) - 1][1] = "Total ="
$aAns[UBound($aAns) - 1][2] = $Total

_ArrayDisplay($aAns, "Target = " & $Target, Default, 0, "|", "Name|Occurrences|Total")
1 person likes this

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

 

 

From what you've posted here, It looks like you're more or less looking for some form of excel calculator. Though I could be mistaken. Here's a example script, With some modification you could get it to do what you're looking for, I think, Possibly with a For Loop;

$A = "Apple"
$B = "Banana"
$C = "Orange"

$A_Quantity = InputBox("Quantity Check", "How many " & $A & "'s do you have?", "", "")
$B_Quantity = InputBox("Quantity Check", "How many " & $B & "'s do you have?", "", "")
$C_Quantity = InputBox("Quantity Check", "How many " & $C & "'s do you have?", "", "")

$A_Result = Number(10 * $A_Quantity)
$B_Result = Number(20 * $B_Quantity)
$C_Result = Number(30 * $C_Quantity)

$Total = Number($A_Result + $B_Result + $C_Result)
If $Total > "200" Then
   MsgBox(0, "Error", "Error: Your Total Exceeds $200", "")
ElseIf $Total <= "200" Then
   MsgBox(0, "Checkout", "" & $A_Quantity & " piece(s) of (" & $A & ") = $10 * " & $A_Quantity & " = $" & $A_Result & "" & @CRLF & "" & $B_Quantity & " piece(s) of (" & $B & ") = $20 * " & $B_Quantity & " = $" & $B_Result & "" & @CRLF & "" & $C_Quantity & " piece(s) of (" & $C & ") = $30 * " & $C_Quantity & " = $" & $C_Result & "" & @CRLF & "" & @CRLF & "Your total is: $" & Number($A_Result + $B_Result + $C_Result) & "")
EndIf

Edit: Added a If statement to check for totals exceeding $200.

 

It's the knapsack problem.

ty guys and i will check knapsack problem

 

Here is a method that returns one result only.

If all possible combinations are required, like:-

21-A's = 21x$10 = $210, and,

19-A's + 1-B = 19x$10 + $20 = $210, etc.

This would be another interpretation which may or may not be required.

#include <Array.au3>

Local $a[3] = [10, 20, 30]
Local $Target = 210 ; 205
Local $Total = 0
Local $Flag = 0
Local $aAns[UBound($a)][3] = [["A = " & $a[0]],["B = " & $a[1]],["C = " & $a[2]]] ; ,["D = " & $a[3]]]

While $Target <> $Total
    $Flag = 0
    For $i = UBound($a) - 1 To 0 Step -1
        If $Total + $a[$i] <= $Target Then
            $Total += $a[$i]
            $aAns[$i][1] += 1
            $aAns[$i][2] += $a[$i]
            $Flag -= 1
            ;ConsoleWrite($Total & @LF)
        Else
            $Flag += 1
        EndIf
        If $Flag = UBound($a) - 1 Then ; When $Target will never equal $Total
            ExitLoop 2
        EndIf
    Next
WEnd

ReDim $aAns[UBound($aAns) + 1][3]
$aAns[UBound($aAns) - 1][1] = "Total ="
$aAns[UBound($aAns) - 1][2] = $Total

_ArrayDisplay($aAns, "Target = " & $Target, Default, 0, "|", "Name|Occurrences|Total")

 

malkey that's amazing _ ty . i will try it

Edited by Space38

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0