Posts: 41
Threads: 13
Joined: Nov 2003
I will try what you posted now, since she is still sleeping.
Thank You all for your help.
WackoWolf
oseph L. Gelsomino
Posts: 41
Threads: 13
Joined: Nov 2003
it seem to be stuck in a loop when it prints "Registered Males"
[/code] READ Number, Age, Gender$, Non.Registered$, Registered$, Vote, N.Vote
DO UNTIL Number$ = "EOF"
IF Age >= 18 THEN
IF Reg$ = "Y" THEN
IF Vote$ = "Y" THEN
Vote = Vote + 1
PRINT "Registerd"
ELSE
N.Vote = N.Vote + 1
PRINT "Eligible and Not Registerd"
END IF
ELSE
IF Gender$ = "F" THEN
NR.Fem = NR.Fem + 1
PRINT "Registerd Female"
ELSE
NR.Male = NR.Male + 1
PRINT "Registerd Male" (this is where is seems to get stuck)
END IF
END IF
ELSE
IF Gender$ = "F" THEN
NE.Fem = NE.Fem + 1
PRINT "Non.Registerd Females"
ELSE
NE.Male = NE.Male + 1
PRINT "Non.Registerd Males "
END IF
END IF
READ Number, Age, Gender$, Registerd$, Registered$, Vote, N.Vote (THIS ALSO COMES UP WITH A SYNTAX ERROR)
LOOP
LET Non.Registerd = NE.Fem + NE.Male
LET Registerd = NR.Fem + NR.Male
LET Vote = NR.Fem + NR.Male
LET N.Votes = Non.Registerd + N.Vote
oseph L. Gelsomino
Posts: 41
Threads: 13
Joined: Nov 2003
Seems like we got it to work except for one small problem. Its not printing the output for the Listing of all the Votes, Could someone help since she has to have this finished for Monday's night class.
Thank You
WackoWolf
Code: '============================================================================
' ************ Gosubs ************
'============================================================================
GOSUB start
GOSUB headings
GOSUB cal
GOSUB final
GOSUB wrap
END
'===========================================================================
' ************ start *************
'===========================================================================
start:
CLS
PRINT
PRINT
a1$ = "Number, Age, Gender$, Registerd$, Vote$"
a2$ = " #### ## \ \ \ \ \ \"
LET zero = 0
RETURN
'============================================================================
' ********** Headings ***********
'============================================================================
headings:
PRINT
PRINT
PRINT
PRINT "==================================================================="
PRINT " Voter Registaion "
PRINT "==================================================================="
PRINT
PRINT a1$
PRINT a2$
PRINT
RETURN
'=============================================================================
' ******** Calulations *************
'============================================================================
cal:
READ Number, Age, Gender$, Registerd$, Vote$
DO UNTIL Number$ = "eof"
' READ Number$, Age, Gender$, Registerd$, Vote$, Vote, N.Vote
' Number = Number + 1
IF Age >= 18 THEN
IF Registerd$ = "Y" THEN
IF Vote$ = "Y" THEN
Vote = Vote + 1
' PRINT "Y"
ELSE
' IF Age < 18 THEN
N.Vote = N.Vote + 1
'PRINT "N"
END IF
ELSE
IF Gender$ = "F" THEN
NR.Fem = NR.Fem + 1
' PRINT "Y"
ELSE
NR.Male = NR.Male + 1
' PRINT "Y"
END IF
END IF
ELSE
IF Gender$ = "F" THEN
NE.Fem = NE.Fem + 1
' PRINT "NVF"
ELSE
NE.Male = NE.Male + 1
' PRINT "NVM "
END IF
END IF
READ Number, Age, Gender$, Registerd$, Vote$
LOOP
LET N.Registerd = NE.Fem + NE.Male
LET Registerd = NR.Fem + NR.Male
LET Vote = NR.Fem + NR.Male
LET N.Votes = Non.Registerd + N.Vote
RETURN
'===========================================================================
' ********* Final *****************
'==========================================================================
'print totals
final:
' N.Vote = NE.Male + NE.Fem + N.Vote
' Registerd$ = NR.Male + NR.Fem
' LET NR.Male = NR.Male
' LET NR.Fem = NR.Fem
' LET NE.Fem = NE.Fem
' LET NE.Male = NE.Male
'===========================================================================
' ******* :-)****************
'===========================================================================
wrap:
PRINT "Total Voters Male"; NR.Male
PRINT "Total Voters Female"; NR.Female
PRINT "Total Non.Registerd Male"; NE.Male
PRINT "Total Non.Registerd Female"; NE.Fem
PRINT "Total Non.Registerd"; N.Vote
PRINT "Total Voters"; Vote
PRINT USING a2$; Number; Age; Gender$; Registerd$; Vote$
RETURN
'***************************************************************************
' ***********DATA***************
'***************************************************************************
DATA 1812, 23, M, Y, Y
DATA 1951, 37, F, Y, Y
DATA 4516, 15, F, N, N
DATA 1654, 19, M, Y, N
DATA 2145, 18, F, N, N
DATA 6233, 21, F, Y, Y
DATA 9127, 22, M, N, N
DATA 3215, 26, F, Y, Y
DATA 2201, 33, F, Y, Y
DATA 7743, 41, M, Y, Y
DATA 1121, 51, F, Y, Y
DATA 1949, 17, M, N, N
DATA eof , , , ,
oseph L. Gelsomino
Posts: 309
Threads: 15
Joined: Jul 2003
First of all we need to clean it up a bit so that it is easier to follow.
I removed the commented out lines and indented so that the structure is more obvious. Code: '============================================================================
' ************ Gosubs ************
'============================================================================
GOSUB start
GOSUB headings
GOSUB cal
GOSUB final
GOSUB wrap
END
'===========================================================================
' ************ start *************
'===========================================================================
start:
CLS
PRINT
PRINT
a1$ = "Number, Age, Gender$, Registerd$, Vote$"
a2$ = " #### ## \ \ \ \ \ \"
LET zero = 0
RETURN
'============================================================================
' ********** Headings ***********
'============================================================================
headings:
PRINT
PRINT
PRINT
PRINT "==================================================================="
PRINT " Voter Registaion "
PRINT "==================================================================="
PRINT
PRINT a1$
PRINT a2$
PRINT
RETURN
'=============================================================================
' ******** Calulations *************
'============================================================================
cal:
READ Number$, Age, Gender$, Registerd$, Vote$ 'The first variable has to be Number$
DO UNTIL Number$ = "eof"
IF Age >= 18 THEN
IF Registerd$ = "Y" THEN
IF Vote$ = "Y" THEN
Vote = Vote + 1
ELSE
N.Vote = N.Vote + 1
END IF
ELSE
IF Gender$ = "F" THEN
NR.Fem = NR.Fem + 1
ELSE
NR.Male = NR.Male + 1
END IF
END IF
ELSE
IF Gender$ = "F" THEN
NE.Fem = NE.Fem + 1
ELSE
NE.Male = NE.Male + 1
END IF
END IF
READ Number$, Age, Gender$, Registerd$, Vote$
LOOP
LET N.Registerd = NE.Fem + NE.Male
LET Registerd = NR.Fem + NR.Male
LET Vote = NR.Fem + NR.Male
LET N.Votes = Non.Registerd + N.Vote
RETURN
'===========================================================================
' ********* Final *****************
'==========================================================================
'print totals
final:
' N.Vote = NE.Male + NE.Fem + N.Vote \
' Registerd$ = NR.Male + NR.Fem | This whole subroutine
' LET NR.Male = NR.Male | has been commented out
' LET NR.Fem = NR.Fem | and should be romoved
' LET NE.Fem = NE.Fem | since it does nothing.
' LET NE.Male = NE.Male /
'===========================================================================
' ******* :-)****************
'===========================================================================
wrap:
PRINT "Total Voters Male"; NR.Male
PRINT "Total Voters Female"; NR.Female
PRINT "Total Non.Registerd Male"; NE.Male
PRINT "Total Non.Registerd Female"; NE.Fem
PRINT "Total Non.Registerd"; N.Vote
PRINT "Total Voters"; Vote
PRINT USING a2$; Number; Age; Gender$; Registerd$; Vote$
RETURN
'***************************************************************************
' ***********DATA***************
'***************************************************************************
DATA 1812, 23, M, Y, Y
DATA 1951, 37, F, Y, Y
DATA 4516, 15, F, N, N
DATA 1654, 19, M, Y, N
DATA 2145, 18, F, N, N
DATA 6233, 21, F, Y, Y
DATA 9127, 22, M, N, N
DATA 3215, 26, F, Y, Y
DATA 2201, 33, F, Y, Y
DATA 7743, 41, M, Y, Y
DATA 1121, 51, F, Y, Y
DATA 1949, 17, M, N, N
DATA eof , , , ,
I also changed Number to Number$ in the READ statements. Otherwise you get an error when it tries to read "eof"
I suggest that you delete the subroutine Final, since it does nothing. Be sure to delete the GOSUB statement that calls it also.
Now look at how you are counting things in the DO loop. You count voters (Vote), non-voters (N.Vote), non-registered females (NR.Fem), non-registered males (NR.Male), non-enfranchised females (NE.Fem) and non-enfranchised males. You never count female and male voters.
When you do some totals after the DO loop, you have Code: LET Registerd = NR.Fem + NR.Male
This says that the total registered = non-registered females + non-registered males
something doesn't seem right here.
Code: LET N.Registerd = NE.Fem + NE.Male
Non-registered = non-enfranchised females + non-enfranchised males
You may wish to include these but don't forget non-registered females and non-registered males.
Code: LET Vote = NR.Fem + NR.Male
The total that voted = non-registered females + non-registered males.
I don't think that you even need this. You already have the total that voted.
Code: LET N.Votes = Non.Registerd + N.Vote
This line is okay except that you should use N.Registerd rather than Non.Registerd (or changed it to Non.Registerd above)
Go through the PRINT statements in the subroutine Wrap the same way. Make sure that each one of them is doing what you want it to do.
hrist Jesus came into the world to save sinners, of whom I am first.(I Timothy 1:15)
For God so loved the world, that He gave His only begotten Son,
that whoever believes in Him should not perish, but have eternal life.(John 3:16)
Posts: 1,813
Threads: 284
Joined: Mar 2003
Posts: 309
Threads: 15
Joined: Jul 2003
For some reason they seem to be taught to use GOSUB in classes. Their teachers must have learned their programming a long time ago.
hrist Jesus came into the world to save sinners, of whom I am first.(I Timothy 1:15)
For God so loved the world, that He gave His only begotten Son,
that whoever believes in Him should not perish, but have eternal life.(John 3:16)
Posts: 2,771
Threads: 96
Joined: Oct 2003
sorry, but I dont see why gosub is so bad. Sure, you could use subs, and sure it makes the code a little unorthadox, but you'll never run into a problem with it. just put all of the gosubed code behind END. not a problemo. =P
Posts: 41
Threads: 13
Joined: Nov 2003
I wish to thank everyone that has help with this program for my friend we finally got it to work with all your help.
Thanks Again
oseph L. Gelsomino
Posts: 309
Threads: 15
Joined: Jul 2003
I'm glad you got it to work.
hrist Jesus came into the world to save sinners, of whom I am first.(I Timothy 1:15)
For God so loved the world, that He gave His only begotten Son,
that whoever believes in Him should not perish, but have eternal life.(John 3:16)
|