Profit or loss

C program to calculate profit and loss on a transaction.

Program

#include<stdio.h>
#include<conio.h>
void main()
{
	float cp, sp;

    printf("Enter the cost price\t:");
    scanf("%f",&cp);
    printf("Enter the selling price\t:");
    scanf("%f",&sp);

    if(cp > sp)
    {
        printf("Loss incurred = %.2f",cp - sp);
    }
    else if(sp > cp)
    {
        printf("Profit incurred = %.2f",sp - cp);
    }
    else
    {
        printf("No Profit and no Loss incurred");
    }

    getch();
}

Output

********** Run1 ********** 

Enter the cost price    :200
Enter the selling price :300
Profit incurred = 100.00


********** Run2 ********** 

Enter the cost price    :534
Enter the selling price :343
Loss incurred = 191.00

Explanation

Cost price and selling price are taken as an input by the user in the variables named 'cp' and 'sp' respectively.
If cost price is greater than selling price then, loss is incurred and is calculated as follows
loss = cp - sp
If selling price is greater than the cost price then, profit is incurred
profit = sp - cp
If seling price and cost price are same, then no loss no profit situation occurs