Ask Experts Questions for FREE Help !
Ask
    andyhaus1057's Avatar
    andyhaus1057 Posts: 98, Reputation: 1
    Junior Member
     
    #1

    Jul 19, 2009, 06:15 PM
    Programming Question.
    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
    donf's Avatar
    donf Posts: 5,679, Reputation: 582
    Printers & Electronics Expert
     
    #2

    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's Avatar
    chuckhole Posts: 850, Reputation: 45
    Senior Member
     
    #3

    Jul 20, 2009, 05:48 AM

    Moved to programming section.
    mindtab's Avatar
    mindtab Posts: 28, Reputation: 0
    New Member
     
    #4

    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

Not your question? Ask your question View similar questions

 

Question Tools Search this Question
Search this Question:

Advanced Search

Add your answer here.


Check out some similar questions!

C programming [ 4 Answers ]

Write and test a function hydroxide that takes a chemical formula as a parameter and returns True if the chemical is a hydroxide (i.e. ends in OH) and returns False otherwise. Example: Enter a chemical formula: NaOH NaOH is a hydroxide. Enter a chemical formula: H2O H2O is not a...

Qt programming [ 1 Answers ]

Hi, My name is anshahmed.I am doing final year B.TECH.Now I am doing a project and I want to use qt programming .Whie I was compiling the qt programm the compiler giving errors in header file(qpplicaton.h) .how can I compile the qt programm.

C programming help [ 1 Answers ]

Hi people I want to shut down my system after a specified time I want to use the time() method but I need to know the exe file that runs after the specified time. Please let me know also if there is any other way to shut down my system after some particular time Thank you Best regards


View more questions Search