计算利润或亏损的 C 程序

如何编写一个计算利润或亏损的 C 程序。如果实际金额小于销售额,则产品盈利。否则,如果实际金额大于销售额,则产品亏损,否则为零。

这个程序帮助用户输入实际金额和销售额来计算利润或亏损。使用这两个值,这个程序将使用Else If语句检查产品是盈利还是亏损。

#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;
}
Program to Calculate Profit or Loss

我试试另一个值

 Please Enter the Actrual Product Cost : 1225.25

 Please Enter the Sale Price (or Selling Price) :  1175.69

 Loss Amount  =  49.5601

另一个

 Please Enter the Actrual Product Cost : 1400

 Please Enter the Sale Price (or Selling Price) :  1400

 No Profit No Loss!