andyhaus1057
Jul 19, 2009, 06:15 PM
Hi,
How would I design nested structures that perform: If amount1 is greater than 10 and amount2 is less than 100, display the greater of amount1 and amount2

donf
Jul 19, 2009, 06:47 PM
Okay, you need to think this through.

You do not have an alternate decision for example:

If amount1 > 10 & amount2 <100
Print the greater variable

What do you do if both statemts are true amount1 =15 amount2 = 95 (print larger number ?)

If one is correct and the other is incorrect - amount1 = 25 amount2 150 (what do you do) What if amount 1 =5 and amount 2 = 50.

Finally what do you do if neither are true:

Amount1 - 3 amount2 = 3000.

Build a decision tree for each statement then build your nested statement for each test criteria you want and then what will you do.

chuckhole
Jul 20, 2009, 05:48 AM
Moved to programming section.

mindtab
Aug 29, 2009, 09:26 AM
I don't know what programming language you are using, but here is an example that should work for you

DECLARE FUNCTION checkamt(lp AS INTEGER) AS INTEGER
DECLARE SUB checknums()

GLOBAL flag AS INTEGER
GLOBAL amt() AS INTEGER
'================================================= ====
FUNCTION PBMAIN () AS LONG
DIM flag AS GLOBAL INTEGER
DIM amt(2) AS GLOBAL INTEGER
DIM I AS INTEGER
DIM response AS STRING, a AS STRING,a1 AS STRING

FOR i=1 TO 2
a\$="Amount "+STR\$(i)
response\$=INPUTBOX\$(a\$,a1)
'option here: call sub to check if valid number input
amt(i)=VAL(response\$)

flag=checkamt(i)
IF flag<>1 THEN
MSGBOX "Amount not within valid range":EXIT FUNCTION
ELSE
END IF
NEXT i

'flag=1 for both numbers, check status of number value
CALL checknums()

END FUNCTION
'================================================= =====
'SUBROUTINES/FUNCTIONS
'=================check amt
FUNCTION checkamt(lp AS INTEGER) AS INTEGER
DIM I AS INTEGER

I=lp
SELECT CASE amt(i)
CASE 11 TO 99
flag=1
CASE ELSE
flag=0
END SELECT

Checkamt=flag
END FUNCTION
'=================check numbers
SUB checknums()
DIM I AS INTEGER, greater AS INTEGER
DIM message AS STRING

Msg\$="":greater=0

IF amt(1)>amt(2) THEN
greater=1
ELSEIF amt(1)=amt(2) THEN
greater=0
ELSE
greater=2
END IF

SELECT CASE greater
CASE 0
msg\$="Amounts are equal "+STR\$(amt(1))+" and "+STR\$(amt(2))
CASE 1
msg\$="Amount 1:("+STR\$(amt(1))+") is greater than amount 2:("+STR\$(amt(2))+")"
CASE 2
msg\$="Amount 2: ("+STR\$(amt(2))+") is greater than amount 1: ("+STR\$(amt(1))+")"
CASE ELSE
msg\$="Unknown error in amount value"
END SELECT

MSGBOX msg\$

END SUB