Calculate the loss incurred in selling the given items at discounted price | C ++ implementation of the approach ; Function to return the x % of n ; Function to return the total loss ; To store the total loss ; Original price of the item ; The price at which the item will be sold ; The discounted price of the item ; Loss incurred ; Driver code ; Total items
#include <bits/stdc++.h> NEW_LINE using namespace std ; float percent ( int n , int x ) { float p = n * x ; p /= 100 ; return p ; } float getLoss ( int price [ ] , int quantity [ ] , int X [ ] , int n ) { float loss = 0 ; for ( int i = 0 ; i < n ; i ++ ) { float originalPrice = price [ i ] ; float sellingPrice = originalPrice + percent ( originalPrice , X [ i ] ) ; float afterDiscount = sellingPrice - percent ( sellingPrice , X [ i ] ) ; loss += ( ( originalPrice - afterDiscount ) * quantity [ i ] ) ; } return loss ; } int main ( ) { int price [ ] = { 20 , 48 , 200 , 100 } ; int quantity [ ] = { 20 , 48 , 1 , 1 } ; int X [ ] = { 0 , 48 , 200 , 5 } ; int n = sizeof ( X ) / sizeof ( X [ 0 ] ) ; cout << getLoss ( price , quantity , X , n ) ; return 0 ; }