Find cost price from given selling price and profit or loss percentage | C ++ implementation to find Cost price ; Function to calculate cost price with profit ; required formula to calculate CP with profit ; Function to calculate cost price with loss ; required formula to calculate CP with loss ; Driver code
#include <iostream> NEW_LINE using namespace std ; float CPwithProfit ( int sellingPrice , int profit ) { float costPrice ; costPrice = ( sellingPrice * 100.0 ) / ( 100 + profit ) ; return costPrice ; } float CPwithLoss ( int sellingPrice , int loss ) { float costPrice ; costPrice = ( sellingPrice * 100.0 ) / ( 100 - loss ) ; return costPrice ; } int main ( ) { int SP , profit , loss ; SP = 1020 ; profit = 20 ; cout << " Cost ▁ Price ▁ = ▁ " << CPwithProfit ( SP , profit ) << endl ; SP = 900 ; loss = 10 ; cout << " Cost ▁ Price ▁ = ▁ " << CPwithLoss ( SP , loss ) << endl ; SP = 42039 ; profit = 8 ; cout << " Cost ▁ Price ▁ = ▁ " << CPwithProfit ( SP , profit ) << endl ; return 0 ; }