Profit and loss if Cost Price and Sell price is given coderinme

Profit and loss

Profit and loss if Cost Price and Sell price is given
If the selling price is more than the cost price, the difference between them is the profit incurred.
Formula: Profit or Gain = S.P. – C.P.
If the selling price is less than the cost price, the difference between them is the loss incurred.
Formula: Loss = Cost price (C.P.) – Selling Price (S.P.)
In other words, if CP>SP then loss = cp-sp
and if SP>CP then profit = sp-cp
we are encoding it in Shell scripting

Let’s code
#!/bin/bash
(bash copy)
read -p "Enter the cost price: " cop
read -p "Enter the selling price: " sep
dif=`expr $sep - $cop`
if (( $dif < 0 )); then
echo "Loss incurred" $dif | tr -d -
else
echo "Profit made "$dif | tr -d -
fi

If you want to learn more about shell then
gross salary problem
shell coding problems

All rights reserved. No part of this Post may be copied, distributed, or transmitted in any form or by any means, without the prior written permission of the website admin, except in the case of brief quotations embodied in critical reviews and certain other noncommercial uses permitted by copyright law. For permission requests, write to the owner, addressed “Attention: Permissions Coordinator” to the admin @coderinme

Leave a reply:

Your email address will not be published.