14 July 2018

TCS CodeVita Problem : Profit or Loss statement for Transactions C-language Program

Problem : Profit or Loss statement for Transactions

www.matterhere.com - Nareddula Rajeev Reddy (NRR)


Input Format:

Input contains three integers N, L, X in each line

Line1
Brokerage rate
Line 2
Buying amount
Line 3
Selling amount
Line 4
Quantity

Assume STT to be fixed at 0.025%, Service Tax to be fixed at 10.36%, Stamp-duty on total turn-over is fixed at 0.002% and Regulatory charge on total turn-over is 0.004%

Output Format:

Print Profit or Loss as applicable with respect to transaction , and in next line print amount profit/loss faced

Line 1
For Valid Input,print
Profit
Or
Loss

For Invalid Input,print
Invalid Input
Line 2
For Valid Input,print
Amount of Profit / Loss faced in transaction

Sample Test Cases:

SNo.InputOutput
1
0.03
315
316
100
Profit
67.42
1
0.03
315
@
100
Invalid Input
1
0.03
315
315.32
100
Loss
0.53


Note:

Participants submitting solutions in C language should not use functions from as these files do not exist in gcc
Note:

This question is inspired by an example of Brokerage calculations provided at
http://www.stockmarketindian.com/calculate_brokerage_charges.html


TCS CodeVita 2013 Round1 Question: Profit or Loss statement for Transactions
C-Language Program (tcs-codevita/profloss.c)

#include <stdio.h>
#include <stdlib.h>

float* arr;
float BR;


int input()
{
arr = malloc(4 * sizeof(float));
int i=0;
while( scanf("%f", &arr[i]) == 1 && i<4 ) 
i++;
if(i<4)
return -1;
else 
return 1;
}

float brokerage(int a)
{
return ((float)a*(BR/100));
}

float servicetax(float a)
{
return ((float) a)* 0.1036;
}

float stt(int a)
{
return (0.00025)*a;
}

int main()
{
float BA,SA,Q,TBA,TSA,BR_b,BR_s,ST,STT,T_b,T_s,X,P,BP,profit;
if(input()==1)
{
BR = arr[0];
BA = arr[1];
SA = arr[2];
Q = arr[3];
TBA = BA * Q;
TSA = SA * Q;
BR_b = brokerage(TBA);
BR_s = brokerage(TSA);
ST = servicetax(BR_b);
STT = stt(TSA);
T_b = BR_b + ST;
T_s = BR_s + STT + ST;
X = T_b + T_s;
P = X + (TBA+TSA) *(0.006/100);
BP = TSA - TBA;
profit = BP - P;
if(profit > 0)
printf("Profit\n%f",profit);
else
printf("Loss\n%f",profit*-1); 
}
else
printf("Invalid Input");

free(arr);
return 1;
}

Sources:
https://www.programminggeek.in/
https://github.com/