QBASIC program to calculate profit and loss percentage
CLS
INPUT
"Enter cost price"; c
INPUT
"Enter selling price:"; s
IF
c > s THEN
l
= ((c - s) / c) * 100
PRINT
"Loss percentage:"; l
ELSEIF
s > c THEN
p
= ((s - c) / c) * 100
PRINT
"Profit percentage:"; p
ELSE
PRINT
"There is neither profit nor loss"
END
IF
END
By using SUB Procedure (SUB…END SUB)
DECLARE
SUB pl ()
CLS
CALL
pl
END
SUB
pl
INPUT
"Enter cost price"; c
INPUT
"Enter selling price:"; s
IF
c > s THEN
l
= ((c - s) / c) * 100
PRINT
"Loss percentage:"; l
ELSEIF
s > c THEN
p
= ((s - c) / c) * 100
PRINT
"Profit percentage:"; p
ELSE
PRINT
"There is neither profit nor loss"
END
IF
END
SUB
By
using FUNCTION procedure (FUNCTION….END FUNCTION)
DECLARE
FUNCTION pl ()
CLS
x
= pl
END
FUNCTION
pl
INPUT
"Enter cost price"; c
INPUT
"Enter selling price:"; s
IF
c > s THEN
l
= ((c - s) / c) * 100
PRINT
"Loss percentage:"; l
ELSEIF
s > c THEN
p
= ((s - c) / c) * 100
PRINT
"Profit percentage:"; p
ELSE
PRINT
"There is neither profit nor loss"
END
IF
END
FUNCTION
Output:
No comments:
Post a Comment