//OrinTill Qimid CS1A Chapter 3, P. 147, #21
//
/**************************************************************
* Calculate profit/loss
*
* ____________________________________________________________
* This program calculate the the money Joe spend on stock his profit/loss and the commission fees.
* ____________________________________________________________
* INPUT
* pshare : the value of the share he bought.
* ashare : the value of the share he sold.
*
* OUTPUT
* total_amount1 : the total amount of share in $ when he bought it.
* total_amount2 : the total amount of share in $ when he sold it.
* commission1 : the commission he payed when buying the stock.
* commission2 : the comission he payed when selling the stock.
* profit : the profit/loss he maded through this trade.
**************************************************************/
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
int main()
{
const int SHAREAMOUNT = 1000;
float pshare = 32.87,
ashare = 33.92,
total_amount1,
total_amount2,
commission1,
commission2,
profit;
total_amount1 = pshare * SHAREAMOUNT;
total_amount2 = ashare * SHAREAMOUNT;
commission1 = total_amount1 * 0.02;
commission2 = total_amount2 * 0.02;
profit = total_amount2 - total_amount1 - commission1 - commission2;
cout<<"Joe spend $"<<total_amount1<<" when purchasing the stock"<<endl;
cout<<"Joe spend $"<<commission1<<" for commission when purchasing the stock."<< endl;
cout<<"Joe sold the stock for $"<<total_amount2<<endl;
cout<<"Joe spend $"<< commission2<<" when selling the stock."<<endl;
cout<<"Joe's profit is $"<<profit<< endl;
return 0;
}
Ly9PcmluVGlsbCBRaW1pZCBDUzFBIENoYXB0ZXIgMywgUC4gMTQ3LCAjMjEKLy8KLyoqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqCiAqIENhbGN1bGF0ZSBwcm9maXQvbG9zcwogKiAKICogX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fCiAqIFRoaXMgcHJvZ3JhbSBjYWxjdWxhdGUgdGhlIHRoZSBtb25leSBKb2Ugc3BlbmQgb24gc3RvY2sgaGlzIHByb2ZpdC9sb3NzIGFuZCB0aGUgY29tbWlzc2lvbiBmZWVzLgogKiBfX19fX19fX19fX19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