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

CCC Online Test 2021 CCC Practice Test Hindi Python Programming Tutorials Best Computer Training Institute in Prayagraj (Allahabad) Best Java Training Institute in Prayagraj (Allahabad) Best Python Training Institute in Prayagraj (Allahabad) O Level Online Test in Hindi Bank SSC Railway TET UPTET Question Bank career counselling in allahabad Sarkari Naukari Notification Best Website and Software Company in Allahabad Sarkari Exam Quiz