Home » CPP Programming Examples For Practice » CPP Programs » Write a C++ program to determine whether the seller has made profit or incurred loss. Also determine how much profit he made or loss he incurred. Cost price and selling price of an item is input by the user.
#include<iostream>usingnamespacestd;intmain(){intcp,sp,result;cout<<"Enter cost price of item : ";cin>>cp;cout<<"Enter selling price of item : ";cin>>sp;result=sp-cp;if(result>0)cout<<"Profit : "<<result;elseif(result<0)cout<<"Loss : "<<-(result);elsecout<<"No profit no loss";cin.ignore();cin.get();return0;}
The Output Is:
SAMPLE RUN # 1
Enter cost price of item : 800
Enter selling price of item : 950
Profit : 150
SAMPLE RUN # 2
Enter cost price of item : 800
Enter selling price of item : 600
Loss : 200
SAMPLE RUN # 3
Enter cost price of item : 800
Enter selling price of item : 800
No profit no loss
Post a Comment