Program to find the profit or loss when CP of N items is equal to SP of M items | C ++ implementation of above formula ; Function to calculate Profit or loss ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; void profitLoss ( int N , int M ) { if ( N == M ) cout << " No ▁ Profit ▁ nor ▁ Loss " ; else { float result = 0.0 ; result = float ( abs ( N - M ) ) / M ; if ( N - M < 0 ) cout << " Loss ▁ = ▁ - " << result * 100 << " % " ; else cout << " Profit ▁ = ▁ " << result * 100 << " % " ; } } int main ( ) { int N = 8 , M = 9 ; profitLoss ( N , M ) ; return 0 ; }