Header Ads Widget

C++ Program to calculate profit or loss by using switch statement

 

 C++  Program to calculate profit or loss by using switch statement

Given cost price and sell price , write a program to calculate profit or loss by using switch case .

Sample input

170 100

Sample output

Loss of 70

 C++  Program to calculate profit or loss by using switch statement

The objective of the code is to find the profit or loss by using switch statement based on cost price and sell price .

Code(C++):-

#include <iostream>
using namespace std;
int main() {
       int cp,sp;
cout<<"Enter the cost price and sell price";
cin>>cp>>sp;
int ch=cp>sp;
switch(ch)
{
case 1:cout<<"Loss of "<<(cp-sp);
break;
case 0:cout<<"Profit of "<<(sp-cp);
break;
}
}

Output:-

Enter the cost price and sell price
170 100
Loss of 70

Recommended Post :-

HCL Coding Questions:-

Capgemini Coding Questions:-

Companies interview:-

Full C course:-    

Key points:-

Cracking the coding interview:-

 Array and string:-

Tree and graph:-

Hackerearth Problems:-

Hackerrank Problems:-

Data structure:-

 MCQs:-