Hi,
I'm stumped with this.. Can you please help?
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
Hi,
I'm stumped with this.. Can you please help?
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
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.
Moved to programming section.
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
All times are GMT -7. The time now is 05:53 PM. |