/***************************************************
Program Stock Market
This program <Is designed to calculate the cost of stock market shares.>
Author: <Eric Goldberg>
Created: <5/18/17>
Revisions: <date> <what changes were made>
***************************************************/
#include <iostream>
#include <iomanip>
#include <cmath>
usingnamespace std;
int main()
{
//Variables
int Shares = 600;
double CostShare = 21.77,
Sell = 2,
BrokerFee = .02,
TotalCostBroker,
TotalBroker,
TotalCost,
Total,
ProfitSell;
// Calculate variables
TotalCost = Shares*CostShare;
TotalBroker = TotalCost * BrokerFee;
Total= TotalBroker + TotalCost;
ProfitSell= Sell / TotalCost;
//Display Data to user.
cout << "The cost of the stocks with out Broker fee: $" << TotalCost << endl;
cout << "The cost of Broker Fees: $" << TotalBroker << endl;
cout << "The Total Cost is: $" << Total << endl;
//Turn a profit
cout << "TO make a profit you will need to sell each stock for: $" << ProfitSell << endl;
return 0;
}
Well, the final answer *is* right, its just that it's rounded because the precision is set lower than a standard calculator, i think. There doesn't appear to be any truncation rounding errors going on in his math. Though, I only took a brief look at the compilation output.
Actually the values differ from my calculator:
0.000150113636022
0.000153116 // From the program.
Which is being caused by floating point errors. If it was just being caused by rounding the last number from the program should be either a 2 or a 4 but not a 6.
Your broker works for free, Aaron.
@jlb's takes his 2% cut.
Therein lies the difference. Who is right depends on the broker. I think the original program should divide by Total in line 37 (giving @jlb's answer) or what it does at present (which gives yours).
It's not the 6th sig fig that is the biggest difference ... it's the 0 or 3 after the ...15...