Question #26170

Ahmed uses the services of a brokerage firm to buy and sell stocks. The firm
charges 1.5% service charges on the total amount for each transaction, buy
or sell. When Ahmed sells stocks, he would like to know if he gained or
lost on a particular investment. Write a program that allows Ahmed to input
the number of shares sold, the purchase price of each share, and the selling price of each share. The program outputs the amount invested, the total service charges, amount gained or lost, and the amount received after selling the stock.

Expert's answer

//Ahmed uses the services of a brokerage firm to buy and sell stocks. The firm
//charges 1.5% service charges on the total amount for each transaction, buy
//or sell. When Ahmed sells stocks, he would like to know if he gained or
//lost on a particular investment. Write a program that allows Ahmed to input
//the number of shares sold, the purchase price of each share, and the selling
//price of each share. The program outputs the amount invested, the total
//service charges, amount gained or lost, and the amount received after
//selling the stock.

# include <iostream>

using namespace std;

int main(){
int n;
cout<<"Enter number:";
cin>>n;
double sp, bp;
double total=0;
for(int i=0;i<n;i++){
cout<<"Enter purchase price:";
cin>>sp;
cout<<"Enter selling price:";
cin>>bp;

cout<<"Cash flow from this operation:";
cout<<bp*0.985 - sp*1.015<<endl;
total+=(bp*0.985 - sp*1.015);
}
cout<<"Total Cash flow:"<<total<<endl;

system("PAUSE");
return 0;
}
LATEST TUTORIALS
APPROVED BY CLIENTS