Programming Examples
Cpp program to check where is profit or loss
Write a cpp program to input cost price, selling price of product from user and check whether is profit or loss and also print the Profit/loss amount.
#include<iostream>
using namespace std;
int main()
{
float cp,sp;
cout<<"Enter cost price";
cin>>cp;
cout<<"Enter selling price";
cin>>sp;
if(cp==sp)
{
cout<<"No profit No loss";
}
else
{
if(cp>sp)
{
cout<<"Loss of "<<cp-sp;
}
else
{
cout<<"Profit of"<<sp-cp;
}
}
return 0;
}
Output
Enter cost price 10
Enter selling price 23
Profit of 13
---------------------------------
Enter cost price 7.9
Enter selling price 8
Profit of 0.0999999