C++ Program to Calculate Profit or Loss

Write a C++ Program to Calculate Profit or Loss with example. This C++ Program allows the user to enter the actual cost of the product and the sale price. Next, we used the Else If statement to check whether the actual cost is less than the sales amount. If True, the product is in profits; otherwise, loss. We used the last else statement (no profit no loss) if both the above conditions fails.

#include<iostream>
using namespace std;

int main()
{
	float unitPrice, salesAmount, amount;
	
	cout << "\nPlease Enter the Actual Product Cost =  ";
	cin >> unitPrice;
	
	cout << "\nPlease Enter the Sale Price (or Selling Price) =  ";
	cin >> salesAmount;
	
	if (salesAmount > unitPrice)
  	{
  		amount = salesAmount - unitPrice;
  		cout << "\nProfit Amount  =  " << amount;
  	}
  	else if(unitPrice > salesAmount)
    {
    	amount = unitPrice - salesAmount;
  		cout << "\nLoss Amount  =  " << amount;
	}
  	else
    	cout << "\nNo Profit No Loss!";
		
 	return 0;
}
C++ Program to Calculate Profit or Loss 1

Let me use the sale price less than the actual price.

Please Enter the Actual Product Cost =  3200

Please Enter the Sale Price (or Selling Price) =  2750

Loss Amount  =  450