Profit or Loss Calculator in C++ || Functions in C++ || Conditional Statements || Functions || C++
In this, we are going to see Functions, the program is based on function which Calculates, Profit or Loss.

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

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

// use underscore for spaces in function name
int profit_and_loss()
{
	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 a;
}

void main()
{
  clrscr();
  profit_and_loss();
  getch();
}
	
    
The code given below can be used for g++/gcc Compiler:-

#include <iostream>
using namespace std;

// use underscore for spaces in function name
int profit_and_loss()
{
	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 a;
}

int main()
{
  profit_and_loss();
  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