Write the algorithm and flowchart to accept the cost price and selling price of any item then print the profit and profit percentage?
Answers
Algorithm:
- Start
- Input CP, SP
- If (SP > CP) then
- P = SP - CP
- P_per = (P / CP) * 100
- Print P and P_per
- Else if (CP > SP) then
- L = CP - SP
- L_per = (L / CP) * 100
- Print L and L_per
- Else
- Print "No profit, no loss"
- End if
- Stop
Program in C++:
#include<iostream>
using namespace std;
int main()
{
double CP, SP;
cout<<"Enter cost price : ";
cin>>CP;
cout<<"Enter selling price : ";
cin>>SP;
if(SP > CP)
{
double P = SP - CP;
double P_per = (P / CP) * 100.0;
cout<<"Profit = "<<P<<endl;
cout<<"Profit percentage = "<<P_per<<"%";
}
else if(CP > SP)
{
double L = CP - SP;
double L_per = (L / CP) * 100.0;
cout<<"Loss = "<<L<<endl;
cout<<"Loss percentage = "<<L_per<<"%";
}
else
{
cout<<"No profit, no loss";
}
return 0;
}
Output 1:
Enter cost price : 100
Enter selling price : 120
Profit = 20
Profit percentage = 20%
Output 2:
Enter cost price : 100
Enter selling price : 80
Loss = 20
Loss percentage = 20%
Output 3:
Enter cost price : 100
Enter selling price : 100
No profit, no loss
Explanation:
This is your prefect answer .
hope it is thankful