Q-Basic – WAP using If-else if statement to find division, precentage and result

WAP which prompts to input name of a student and marks obtained in 5 subjects and then prints total, percentage, result and division.

 

This program in Q-Basic is an example of using if-else if statement to categorize division obtained by students with the total marks of five subjects. If-else if statement in this program checks whether the percentage obtained by the student is greater or less than the bound limit percentage to score a particular division. When percentage of the student is greater than one bound limit then the statement inside if clause is executed, if not then the statement inside else clause is executed.

 


CLS

   SUM = 0

   R$= “PASSED”

   I = 1

   INPUT “NO. OF STUDENTS”; N

10:

   INPUT “ENTER THE NAME OF THE STUDENTS”; N$

   J = 1

20:

   INPUT “ENTER MARKS”; X

   SUM = SUM + X

   J = J + 1

   IF J <= 5 THEN GOTO 20

      PCT = SUM/ 5

        IF PCT>= 40 THEN

          R$= “PASSED”

        ELSE

          R$ = “FAILED”

        IF PCT>= 80 THEN

          D$= “DISTINCTION”

        ELSE IF PCT>=60 THEN

          D$= “FIRST”

        ELSE IF PCT>=45 THEN

          D$ = “SECOND”

        ELSE

          D$ = “THIRD”

        END IF

      ELSE

        D$ = “YOU HAVE NO DIVISION:

      END IF

  PRINT “NAME=”; N$

  PRINT “TOTAL MARKS =”; SUM

  PRINT “PERCENTAGE=”; PCT; “%”

  PRINT “RESULT=”; R$

  PRINT “DIVISION=”; D$

  SUM = 0: R$ = “PASSED”

  I = I + 1

  IF I <=N GOTO 10

  END

 

For more programs in Q-Basic Click Here