write a Qbasic program to print the total number of boys and girls in your class
Answers
Write a program in QBasic to count number of male and female students in class. Print out the number of males, number of females and total number of students.
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/**
*
* @Author: Aghatise Osazuwa
* Website: www.cscprogrammingtutorials.com
*
*/
DIM nTotal AS Integer, nMale AS INTEGER, nFemale AS INTEGER
DIM choice AS Integer, sex AS INTEGER, female AS INTEGER
nTotal = 0
nMale = 0
nFemale = 0
PRINT ""
PRINT "THIS PROGRAM COUNTS AND PRINTS THE NUMBER OF MALES AND FEMALES IN A CLASS"
PRINT "-------------------------------------------------------------------------"
PRINT ""
INPUT "DO you want to start (-1 to quit)"; choice
DO WHILE choice <> -1
INPUT "Is student a male (1 = yes, 2 = no)"; sex
IF sex = 1 THEN
nMale = nMale + 1
ELSE
nFemale = nFemale + 1
ENDIF
nTotal = nTotal + 1
INPUT "DO you want to continue (-1 to quit)"; choice
LOOP
PRINT ""
PRINT "The total number of MALE students = "; nMale
PRINT "The total number of FEMALE students = "; nFemale
PRINT "The total number of students = "; nTotal
CLS
SCREEN 13
PRINT "CALCULATOR-"
PRINT "ENTER YOUR EXPRESSION"
PRINT "EXAMPLE-58 * 20"
PRINT "THE TERMS SHOULD BE SEPARATED BY SPACE OR ERROR WILL OCCUR"
INPUT "ENTER YOUR EXPRESSION-"; EXP$
EXP$ = EXP$ + " "
INDEX = 1
DIM TERMS(3) AS INTEGER
FOR I = 1 TO LEN(EXP$)
CURRENTTOKEN$ = MID$(EXP$, I, 1)
IF CURRENTTOKEN$ = " " THEN
IF INDEX = 2 AND OPERATION$ = "" THEN
OPERATION$ = TERMCURRENT$
ELSE
TERMS(INDEX) = VAL(TERMCURRENT$)
INDEX = INDEX + 1
END IF
TERMCURRENT$ = ""
ELSE
TERMCURRENT$ = TERMCURRENT$ + CURRENTTOKEN$
END IF
NEXT I
SELECT CASE OPERATION$
CASE "+"
R = TERMS(1) + TERMS(2)
CASE "*"
R = TERMS(1) * TERMS(2)
CASE "-"
R = TERMS(1) - TERMS(2)
CASE "/"
R = TERMS(1) / TERMS(2)
CASE "%"
R = TERMS(1) MOD TERMS(2)
CASE "^"
R = TERMS(1) ^ TERMS(2)
END SELECT
PRINT TERMS(1); OPERATION$; TERMS(2); "="; R