Suppose a business has hired you as a programmer to develop their profit and lost System. And being software developer you have to analyze their last three years data. The business requirements are as follow. If the price of selling and price of cost of a good or product is entered through keyboard. You need to write the code for finding whether the seller (business) has made profit out of business or has suffered loss, you should also find out how much profit or loss has been made by the business in these three years
#include <iostream>
#include <string>
using namespace std;
//main method
int main(){
float sellingPrice;
float priceGood;
float profit=0;
float loss=0;
// If the price of selling and price of cost of a good or product is entered through keyboard.
for(int year=1; year<=3; year++){
cout<<"Enter the price of selling for year "<<year<<": ";
cin>>sellingPrice;
cout<<"Enter the price of cost of a good or product for year "<<year<<": ";
cin>>priceGood;
// finding whether the seller (business) has made profit out of business or has suffered loss,
if(sellingPrice>priceGood){
cout<<"\nThe seller (business) has made profit.\n\n";
//find out how much profit or loss has been made by the business in these three years
profit+=(sellingPrice-priceGood);
}else{
cout<<"\nThe seller (business) has suffered loss.\n\n";
loss+=(priceGood-sellingPrice);
}
}
cout<<profit<<" profit has been made by the business in these three years.\n";
cout<<loss<<" loss has been made by the business in these three years.\n\n\n";
system("pause");
return 0;
}
Comments
Leave a comment