How to Write a C Program to Calculate Profit or Loss. If the actual amount is less than the Sales, then the product is in profit. Otherwise, if the actual is greater than the Sale amount product is in Loss otherwise, none.
This program helps the user to enter the actual and Sales Amounts to Calculate Profit or Loss. Using those two values, this Program will check whether the product is in profit or Loss using Else If. For more topics, refer to the C programs article.
#include<stdio.h>
int main()
{
float Unit_Price, Sales_Amount, Amount;
printf("\n Please Enter the Actrual Product Cost : ");
scanf("%f", &Unit_Price);
printf("\n Please Enter the Sale Price (or Selling Price) : ");
scanf("%f", &Sales_Amount);
if (Sales_Amount > Unit_Price)
{
Amount = Sales_Amount - Unit_Price;
printf("\n Profit Amount = %.4f", Amount);
}
else if(Unit_Price > Sales_Amount)
{
Amount = Unit_Price - Sales_Amount;
printf("\n Loss Amount = %.4f", Amount);
}
else
printf("\n No Profit No Loss!");
return 0;
}

Let me try another value. Also, check out the C Else If statement to understand the logic.
Please Enter the Actrual Product Cost : 1225.25
Please Enter the Sale Price (or Selling Price) : 1175.69
Loss Amount = 49.5601
another one
Please Enter the Actrual Product Cost : 1400
Please Enter the Sale Price (or Selling Price) : 1400
No Profit No Loss!
Also Read
- C Program to Print an Integer, Character, and Float Value
- C Program to find the size of int, float, double, and char