Profit or Loss Calculator in C++ || Conditional Statements || C++
In this we are going to see how to make a basic Profit or Loss Calculator Program in C++.

The code given below can be used for TURBO C++ Compiler:-

#include <iostream.h>
#include <conio.h>

void main()
{
        clrscr();
	int cp, sp, diff, a;
	cout << "Enter the cost price\n";
	cin >> cp;
	cout << "Enter selling price\n";
	cin >> sp;
	diff = sp - cp;
	a = (diff * 100) / cp;
	if (diff > 0)
	{
		cout << "You had a profit of :" << a << " percentage" << endl;
		if (a >= 50)
		{
			cout << "You had a great deal !!!!!" << endl;
		}
		else
			cout << "You had an average deal" << endl;
	}

	else if (diff < 0)
	{
		cout << "You have incurred a loss of :" << a << " percentage";
	}
	getch();
}
    
    

The code given below can be used for g++/gcc Compiler:-

#include <iostream>
using namespace std;

int main()
{
	int cp, sp, diff, a;
	cout << "Enter the cost price\n";
	cin >> cp;
	cout << "Enter selling price\n";
	cin >> sp;
	diff = sp - cp;
	a = (diff * 100) / cp;
	if (diff > 0)
	{
		cout << "You had a profit of :" << a << " percentage" << endl;
		if (a >= 50)
		{
			cout << "You had a great deal !!!!!" << endl;
		}
		else
			cout << "You had an average deal" << endl;
	}

	else if (diff < 0)
	{
		cout << "You have incurred a loss of :" << a << " percentage";
	}
	return 0;
}
    
    

#ENJOY CODING

Post a Comment

FOR ANY DOUBTS AND ERRORS FEEL FREE TO ASK. YOUR DOUBTS WILL BE ADDRESSED ASAP

Previous Post Next Post