help!!!!!!!
Posted: Fri Jan 16, 2004 4:57 am
I'm learning QBasic and I'm not very good at it yet. I wrote a program that adds ,subtracts,multiplies or divides fractions. The output is decimal. For some reason it doesn't work. I have no idea why plese help me !!!!!!! ???
this is the program:
DECLARE SUB enter (numerator!(), denumerator!(), op$(), count!)
DECLARE SUB process (numerator!(), denumerator!(), op$(), count!, answer!)
DECLARE FUNCTION plus! (numerator!(), denumerator!(), answer!, i!)
DECLARE FUNCTION minus! (numerator!(), denumerator!(), answer!, i!)
DECLARE FUNCTION times! (numerator!(), denumerator!(), answer!, i!)
DECLARE FUNCTION divide! (numerator!(), denumerator!(), answer!, i!)
DECLARE SUB display (answer!)
CLS
DIM numerator(1 TO 150)
DIM denumerator(1 TO 150)
DIM op$(1 TO 150)
CALL enter(numerator(), denumerator(), op$(), count)
CALL process(numerator(), denumerator(), op$(), count, answer)
PRINT
CALL display(answer)
END
SUB display (answer)
PRINT answer * 2
END SUB
FUNCTION divide (numerator(), denumerator(), answer, i)
LET divide = answer / (1 / denumerator(i) * numerator(i))
END FUNCTION
SUB enter (numerator(), denumerator(), op$(), count)
LET count = 1
DO
INPUT "numerator", numerator(count)
INPUT "denumerator", denumerator(count)
INPUT "operation", op$(count)
LOOP UNTIL op$(count) = "="
END SUB
FUNCTION minus (numerator(), denumerator(), answer, i)
LET minus = answer - (1 / denumerator(i) * numerator(i))
END FUNCTION
FUNCTION plus (numerator(), denumerator(), answer, i)
LET plus = answer + (1 / denumerator(i) * numerator(i))
END FUNCTION
SUB process (numerator(), denumerator(), op$(), count, answer)
LET answer = (1 / denumerator(1)) * numerator(1)
FOR i = 2 TO count
SELECT CASE op$(i)
CASE IS = "+"
LET answer = plus(numerator(), denumerator(), answer, i)
CASE IS = "-"
LET answer = minus(numerator(), denumerator(), answer, i)
CASE IS = "*"
LET answer = times(numerator(), denumerator(), answer, i)
CASE IS = "/"
LET answer = times(numerator(), denumerator(), answer, i)
END SELECT
NEXT i
END SUB
FUNCTION times (numerator(), denumerator(), answer, i)
LET times = answer * (1 / denumerator(i) * numerator(i))
END FUNCTION
this is the program:
DECLARE SUB enter (numerator!(), denumerator!(), op$(), count!)
DECLARE SUB process (numerator!(), denumerator!(), op$(), count!, answer!)
DECLARE FUNCTION plus! (numerator!(), denumerator!(), answer!, i!)
DECLARE FUNCTION minus! (numerator!(), denumerator!(), answer!, i!)
DECLARE FUNCTION times! (numerator!(), denumerator!(), answer!, i!)
DECLARE FUNCTION divide! (numerator!(), denumerator!(), answer!, i!)
DECLARE SUB display (answer!)
CLS
DIM numerator(1 TO 150)
DIM denumerator(1 TO 150)
DIM op$(1 TO 150)
CALL enter(numerator(), denumerator(), op$(), count)
CALL process(numerator(), denumerator(), op$(), count, answer)
CALL display(answer)
END
SUB display (answer)
PRINT answer * 2
END SUB
FUNCTION divide (numerator(), denumerator(), answer, i)
LET divide = answer / (1 / denumerator(i) * numerator(i))
END FUNCTION
SUB enter (numerator(), denumerator(), op$(), count)
LET count = 1
DO
INPUT "numerator", numerator(count)
INPUT "denumerator", denumerator(count)
INPUT "operation", op$(count)
LOOP UNTIL op$(count) = "="
END SUB
FUNCTION minus (numerator(), denumerator(), answer, i)
LET minus = answer - (1 / denumerator(i) * numerator(i))
END FUNCTION
FUNCTION plus (numerator(), denumerator(), answer, i)
LET plus = answer + (1 / denumerator(i) * numerator(i))
END FUNCTION
SUB process (numerator(), denumerator(), op$(), count, answer)
LET answer = (1 / denumerator(1)) * numerator(1)
FOR i = 2 TO count
SELECT CASE op$(i)
CASE IS = "+"
LET answer = plus(numerator(), denumerator(), answer, i)
CASE IS = "-"
LET answer = minus(numerator(), denumerator(), answer, i)
CASE IS = "*"
LET answer = times(numerator(), denumerator(), answer, i)
CASE IS = "/"
LET answer = times(numerator(), denumerator(), answer, i)
END SELECT
NEXT i
END SUB
FUNCTION times (numerator(), denumerator(), answer, i)
LET times = answer * (1 / denumerator(i) * numerator(i))
END FUNCTION