fork download
  1. //OrinTill Qimid CS1A Chapter 3, P. 147, #21
  2. //
  3. /**************************************************************
  4.  * Calculate profit/loss
  5.  *
  6.  * ____________________________________________________________
  7.  * This program calculate the the money Joe spend on stock his profit/loss and the commission fees.
  8.  * ____________________________________________________________
  9.  * INPUT
  10.  * pshare : the value of the share he bought.
  11.  * ashare : the value of the share he sold.
  12.  *
  13.  * OUTPUT
  14.  * total_amount1 : the total amount of share in $ when he bought it.
  15.  * total_amount2 : the total amount of share in $ when he sold it.
  16.  * commission1 : the commission he payed when buying the stock.
  17.  * commission2 : the comission he payed when selling the stock.
  18.  * profit : the profit/loss he maded through this trade.
  19.  **************************************************************/
  20. #include <iostream>
  21. #include <iomanip>
  22. #include <cmath>
  23. using namespace std;
  24.  
  25. int main()
  26. {
  27. const int SHAREAMOUNT = 1000;
  28. float pshare = 32.87,
  29. ashare = 33.92,
  30. total_amount1,
  31. total_amount2,
  32. commission1,
  33. commission2,
  34. profit;
  35. total_amount1 = pshare * SHAREAMOUNT;
  36. total_amount2 = ashare * SHAREAMOUNT;
  37. commission1 = total_amount1 * 0.02;
  38. commission2 = total_amount2 * 0.02;
  39. profit = total_amount2 - total_amount1 - commission1 - commission2;
  40. cout<<"Joe spend $"<<total_amount1<<" when purchasing the stock"<<endl;
  41. cout<<"Joe spend $"<<commission1<<" for commission when purchasing the stock."<< endl;
  42. cout<<"Joe sold the stock for $"<<total_amount2<<endl;
  43. cout<<"Joe spend $"<< commission2<<" when selling the stock."<<endl;
  44. cout<<"Joe's profit is $"<<profit<< endl;
  45.  
  46.  
  47.  
  48.  
  49. return 0;
  50. }
Success #stdin #stdout 0s 5284KB
stdin
Standard input is empty
stdout
Standard output is empty