help!!!!!!!
Moderators:Administrator, Global Moderator
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
- frankiebaby
- Global Moderator
- Posts:95
- Joined:Tue Apr 30, 2002 1:38 am
- Location:Pennsylvania
- Contact:
Re: help!!!!!!!
Try this out, u made a few simple mistakes, and i made some changes to simplify the 'fraction making' process
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 not entirely sure why this *2 is here, so i removed it
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)
count = count + 1 ' you were missing this!
LOOP UNTIL op$(count - 1) = "=" 'to adjust to adding one, subtract one
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 + (numerator(i) / denumerator(i))
END FUNCTION
SUB process (numerator(), denumerator(), op$(), count, answer)
'LET answer = (1 / denumerator(1)) * numerator(1)
LET answer = numerator(1) / denumerator(1)
FOR i = 2 TO count
SELECT CASE op$(i - 1) 'changed this, you want the last one's op, not this new one's
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
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 not entirely sure why this *2 is here, so i removed it
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)
count = count + 1 ' you were missing this!
LOOP UNTIL op$(count - 1) = "=" 'to adjust to adding one, subtract one
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 + (numerator(i) / denumerator(i))
END FUNCTION
SUB process (numerator(), denumerator(), op$(), count, answer)
'LET answer = (1 / denumerator(1)) * numerator(1)
LET answer = numerator(1) / denumerator(1)
FOR i = 2 TO count
SELECT CASE op$(i - 1) 'changed this, you want the last one's op, not this new one's
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
Re: help!!!!!!!
Thanks a lot for helping me :). I tried it and it works perfectly now. I'm just wondering why after :
LET answer=[1/denumerator[1]] * numerator[1]
you put :
LET answer=denumerator[1] / numerator[1]
I'm very grateful for you fixing my program, but I would like to know why you put in that line , so in the future I won't make any more mistakes.
LET answer=[1/denumerator[1]] * numerator[1]
you put :
LET answer=denumerator[1] / numerator[1]
I'm very grateful for you fixing my program, but I would like to know why you put in that line , so in the future I won't make any more mistakes.
- frankiebaby
- Global Moderator
- Posts:95
- Joined:Tue Apr 30, 2002 1:38 am
- Location:Pennsylvania
- Contact:
Re: help!!!!!!!
well, i wasnt too sure about this one:
LET answer=(1/denumerator(1)) * numerator(1)
b/c it just seems to be more work than neccesary to get the decimal form of the fraction.
this will return the same answer, only it uses fewer operations and no parenthesis. This makes it easier to read and faster when executing. Not that speed matters much in this application, but in another it might.
LET answer=denumerator(1) / numerator(1)
LET answer=(1/denumerator(1)) * numerator(1)
b/c it just seems to be more work than neccesary to get the decimal form of the fraction.
this will return the same answer, only it uses fewer operations and no parenthesis. This makes it easier to read and faster when executing. Not that speed matters much in this application, but in another it might.
LET answer=denumerator(1) / numerator(1)
Re: help!!!!!!!
Thanks a lot for explaining this to me
Re: help!!!!!!!
This is a program that finds the mode of an array. nathanj posted a question on how to do it. I wrote the program that finds the mode but it doesn't quite work.
See what it does it displays the total numeber of numbers not the number of times the mode ocurrs.
Here's the code:
DECLARE SUB mode (m!(), check!(), num!)
DECLARE SUB bubble (check!(), num!)
CLS
DIM m(1 TO 5)
DIM check(1 TO 5)
CALL mode(m(), check(), num)
CALL bubble(check(), num)
PRINT check(1)
DATA 40,50,40,30,40
END
SUB bubble (check(), num)
FOR i = 1 TO num - 1
FOR n = 1 TO n - num
IF check(n) < check(n + 1) THEN
SWAP check(n), check(n + 1)
END IF
NEXT n
NEXT i
END SUB
SUB mode (m(), check(), num)
FOR i = 1 TO 5
DO WHILE num < 5
LET num = num + 1
IF m(i) = m(num) THEN
LET check(i) = check(i) + 1
END IF
LOOP
LET num = 0
NEXT i
END SUB
What it does is it checks if the first number equals any other numbers and if it does it adds one to count.
Then it orders the count array and displays the first of the array. I worked on it for two days and I don't know what the hell is wrong with this program :o.
Can you please help me [and nathanj too].
Also if anybody wants help with anything they can post it here.
See what it does it displays the total numeber of numbers not the number of times the mode ocurrs.
Here's the code:
Code: Select all
DECLARE SUB bubble (check!(), num!)
CLS
DIM m(1 TO 5)
DIM check(1 TO 5)
CALL mode(m(), check(), num)
CALL bubble(check(), num)
PRINT check(1)
DATA 40,50,40,30,40
END
SUB bubble (check(), num)
FOR i = 1 TO num - 1
FOR n = 1 TO n - num
IF check(n) < check(n + 1) THEN
SWAP check(n), check(n + 1)
END IF
NEXT n
NEXT i
END SUB
SUB mode (m(), check(), num)
FOR i = 1 TO 5
DO WHILE num < 5
LET num = num + 1
IF m(i) = m(num) THEN
LET check(i) = check(i) + 1
END IF
LOOP
LET num = 0
NEXT i
END SUB
What it does is it checks if the first number equals any other numbers and if it does it adds one to count.
Then it orders the count array and displays the first of the array. I worked on it for two days and I don't know what the hell is wrong with this program :o.
Can you please help me [and nathanj too].
Also if anybody wants help with anything they can post it here.
- frankiebaby
- Global Moderator
- Posts:95
- Joined:Tue Apr 30, 2002 1:38 am
- Location:Pennsylvania
- Contact:
Re: help!!!!!!!
ok, heres a way to find the mode, but there is some redundancy, so its not extremely efficient, oh well:
(note, does not ned sorted data)
CONST numdata = 5' how many number to have
DIM array(numdata) AS INTEGER
'fill the array with numbers first, im not going to show you that :P
MAX = 0
NUM = 0
FOR count = 0 to numdata - 1 'pick which number to look for
CURRENT = array(count)
MANY = 0 'how many times it shows up
FOR count2 = count to numdata - 1
IF array (count2) = CURRENT THEN MANY = MANY + 1 ' count how many times it shows up
NEXT
IF MANY > MAX THEN
NUM = CURRENT 'if it beats the record, mark it
MAX = MANY
END IF
NEXT
PRINT "THE MODE IS "; NUM; ", OCCURING "; MAX; " TIMES!"
(note, does not ned sorted data)
CONST numdata = 5' how many number to have
DIM array(numdata) AS INTEGER
'fill the array with numbers first, im not going to show you that :P
MAX = 0
NUM = 0
FOR count = 0 to numdata - 1 'pick which number to look for
CURRENT = array(count)
MANY = 0 'how many times it shows up
FOR count2 = count to numdata - 1
IF array (count2) = CURRENT THEN MANY = MANY + 1 ' count how many times it shows up
NEXT
IF MANY > MAX THEN
NUM = CURRENT 'if it beats the record, mark it
MAX = MANY
END IF
NEXT
PRINT "THE MODE IS "; NUM; ", OCCURING "; MAX; " TIMES!"
Re: help!!!!!!!
thanks for the help
;D >:( ??? ::) :-[ :-X :-/ :-* :'(
;D >:( ??? ::) :-[ :-X :-/ :-* :'(