Table of Contents
Overview
Below is the QBASIC program to determine whether there is profit or loss and display the profit or loss amount.
REM Program to check profit or loss
CLS
INPUT "Enter the cost price: "; cp
INPUT "Enter the selling price: "; sp
IF cp > sp THEN
loss = cp - sp
PRINT "You have loss and the loss amount is "; loss
ELSE IF sp > cp THEN
profit = sp - cp
PRINT "You have profit and the profit amount is "; profit
ELSE
PRINT "You dont have any profit or loss"
END IF
END
Output
Explanation
To check whether there is loss or profit, we need cost price and selling price from the user and if the cost price is greater than the selling price, there is loss and loss is the difference of cost price and selling price (loss = cp – sp).
Similarly, if the selling price is greater than the cost price, there is profit and profit is the difference between the selling price and cost price (profit = sp – cp).
If the selling price and the cost price is equal, there is no loss or profit.
More Programs
https://thinkshare.one/learn/programming/qbasic/