Site icon T4Tutorials.com

Write a C program to calculate profit or loss switch statement

Write a C++ program to calculate profit or loss by using the switch statement.

C++ Source Code to calculate profit or loss – switch statement

#include<iostream>
using namespace std;
int main()
{
	int purchase,sale,profit_loss;
	cout<<"Enter Your Purcahsing Price : ";
	cin>>purchase;
	cout<<"Enter Your Selling Price : ";
	cin>>sale;
	switch(sale>purchase)
	{
		case 1: 
		profit_loss=sale-purchase;
		cout<<"You got the Profit  and your profit is: "<<profit_loss;
		break;
		case 0:
		profit_loss=sale-purchase;
		cout<<"You got loss and Your Loss is : "<<profit_loss;
		break;		
	}
}

Output

Enter Your Purchasing Price : 400

Enter Your Selling Price : 200

You got loss and Your Loss is: -200

Flowchart of the profit or loss program by using the switch statement

Flowchart of the profit or loss program by using the switch statement

SFT (Shamil’s Flow Table )

Are you interested to Read about SFT(Shamil’s Flow Table)?

Explanation of the profit loss program by using the switch statementprofit or loss program by using if else

Exit mobile version