Having issues with Mindtap coding

This is my code which I wrote for the following assignment. 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 amount invested
The total service charges
Amount gained or lost
The amount received after selling the stock.

Now I keep getting the message: How many shares did you sell which tells me that the code is running properly and there are no syntax errors. However I am supposed to run a test cast with the following information: Test case 1

Input
76.43
88.55
43
Output

Results
3335.793750.54106.412414.748
Expected Output
3335.793750.54106.412414.748

My output must be able to calculate one or all of the following results. My code is attached below. I cannot for the life of me figure out where I am supposed to put these inputs in the code I wrote in order for the run check to work. If anyone has any ideas I would greatly appreciate the help.

#include <iostream>
#include <iomanip>


using namespace std;

int main(){
const double BROKERAGE_FEE = 0.015;
double purchasePrice, salePrice, netAmount, originalInvestment, totalFees;
int sharesSold;

cout << "How many shares did you sell? ";
cin >> sharesSold;
cout << "What was the sale price: $";
cin >> salePrice;
cout << "What was the purchase price: $";
cin >> purchasePrice;

originalInvestment = sharesSold * purchasePrice;
totalFees = (sharesSold * salePrice) * BROKERAGE_FEE;
netAmount = (sharesSold * salePrice) - totalFees;

cout << fixed << showpoint << setprecision(2);

cout << "Amount invested: $" << originalInvestment << endl;
cout << "Service charges: $" << totalFees << endl;
cout << "Profit / Loss: $" << netAmount - originalInvestment << endl;
return 0;
}
your design is not friendly to the task, but one way to do it would be this:
double sharesSold = 76.43;
double salePrice = 88.55;
bool runningtestcase = argv[1]; //maybe running the test case is done with command line args?
etc.
then down below:
if(!runningtestcase)
cin >> sharesSold;
//else do nothing and use the default value from initialize...

does this make sense?

however it is likely the teacher just wants you to type in the values given to test the code, not to hard code a test case into the code. They probably, at this point in your studies, just want you to run the program and check your answer by hand.
Last edited on
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

Your code has:
1
2
3
4
5
6
cout << "How many shares did you sell? ";
cin >> sharesSold;
cout << "What was the sale price: $";
cin >> salePrice;
cout << "What was the purchase price: $";
cin >> purchasePrice;
So you're asking for the data in the wrong order. Since they give sample input and output, you should input the data in the order given.

The firm charges 1.5% service charges on the total amount for each transaction
There are two transactions: one when you buy and one when you sell. You're computing the service charge on the sale only. Note that the amount of each transaction is different so you can't just double the charge on the sale.
Topic archived. No new replies allowed.