Answer to Question #26744 in C++ for Eman

Question #26744
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];
}

double total_services_charges = (amount_invested + amount_after_selling) * 0.015;

double amount_gained = amount_after_selling - (amount_invested + total_services_charges);

cout << "Amount invested: " << amount_invested << endl;

cout << "Total services charges: " << total_services_charges << "\n";

if (amount_gained < 0)
& cout << "You lost: " << fabs(amount_gained) << "\n";
else
& if (amount_gained == 0)
& cout << "Your balance did not change" << "\n";
& else
& cout << "You gained: " << amount_gained << "\n";

cout << "Amount, recieved after selling stocks: " << amount_after_selling << "\n";

system("PAUSE");
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS