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.
2
1
Expert's answer
2013-03-29T11:34:14-0400
#include <iostream> #include <vector>
using namespace std;
int main() { char ch; cout << "Please, enter the number of shares sold\n"; int shares_number = 0;
cin >> shares_number;
if (!shares_number) { & system("PAUSE"); & return 0; }&
cout << "Please, enter the purchase price of each share (separate them with spaces)\n"; vector<double> purchace_price; double purch_price; for (int i = 0; i < shares_number; i++) { & cin >> purch_price; & purchace_price.push_back(purch_price); }
cout << "Please, enter the selling price of each share (separate them with spaces)\n"; vector<double> selling_price; double sell_price; for (int i = 0; i < shares_number; i++) { & cin >> sell_price; & selling_price.push_back(sell_price); }
double amount_invested = 0; for (int i = 0; i < shares_number; i++) { & amount_invested += purchace_price[i]; }
double amount_after_selling = 0; for (int i = 0; i < shares_number; i++) { & amount_after_selling += selling_price[i]; }
Comments
Leave a comment