Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ Cindy uses the services of a brokerage firm to buy and sell stocks. The firm charges 1.5% service charges on the total amount for

C++

Cindy 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 Cindy sells stocks, she would like to know if she gained or lost on a particular investment.

Instructions

Write a program that allows Cindy to input:

The purchase price of each share

The selling price of each share

The number of shares sold

The program outputs:

The total amount invested

The total amount received from selling

The total service charges

Amount gained or lost

An example program is shown below:

Enter the buying price of each share: 13.23 Enter the selling price of each share: 14.00 Enter the number of shares sold: 43 Total amount invested: $ 577.423 Total amount received: $ 592.97 Total service charges: $ 17.5633 Amount gained or lost: $15.5466

Since your program handles currency, make sure to use a data type that can store decimals.

My current code that isn't working..

#include

using namespace std;

const double service_Charge = 0.015;

int main() {

float soldShares;

double sharePurchase;

double shareSell;

double amountInvested;

double amountReceived;

double buyServiceCharge;

double sellServiceCharge;

double totalServiceCharge;

double gainedOrLost;

cout << "Enter number of shares sold ";

cin >> soldShares;

cout << "Enter purchase price of share ";

cin >> sharePurchase;

cout << "Enter sale price of share ";

cin >> shareSell;

buyServiceCharge = service_Charge * (soldShares * sharePurchase);

sellServiceCharge = service_Charge * (soldShares * shareSell);

totalServiceCharge = buyServiceCharge + sellServiceCharge;

amountInvested = (soldShares * sharePurchase) + buyServiceCharge;

cout << "Invested Amount " << amountInvested << endl;

cout << "Total Service Charges " << totalServiceCharge << endl;

gainedOrLost =

(soldShares * (shareSell - sharePurchase)) - totalServiceCharge;

if (gainedOrLost > 0)

cout << "Gained Amount " << gainedOrLost << endl;

else

cout << "Lost Amount " << (gainedOrLost * -1) << endl;

amountReceived = (soldShares * shareSell) - sellServiceCharge;

cout << "Amount Received " << amountReceived << endl;

// system("PAUSE");

return 0;

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Systems An Application Oriented Approach Complete Version

Authors: Michael Kifer, Arthur Bernstein, Richard Lewis

2nd Edition

0321268458, 978-0321268457

Students also viewed these Databases questions