Advertisement
Guest User

Untitled

a guest
Oct 24th, 2016
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <cmath>
  4. using namespace std;
  5.  
  6. double stock(int shares, double purPrice, double buyComm, double salePrice, double saleComm);
  7.  
  8. {
  9. double profit = ((shares * salePrice) - saleComm) - ((shares * purPrice) + buyComm);
  10.  
  11. return profit;
  12. }
  13. int main()
  14. {
  15. int numShares;
  16. double salePrice, saleCommission, purchasePrice, purchaseCommission, profit_or_loss;
  17.  
  18. while (numShares != -99)
  19. {
  20. cout << endl << "Enter -1 to get the profit." << endl;
  21. cout << "Number of shares purchased: ";
  22. cin >> numShares;
  23. if (numShares != -1)
  24. {
  25. cout << "Purchase Price per share: ";
  26. cin >> purchasePrice;
  27. cout << "Purchase Commission Paid: ";
  28. cin >> purchaseCommission;
  29. cout << "Sale Price per Share: ";
  30. cin >> salePrice;
  31. cout << "Sale Commission Paid: ";
  32. cin >> saleCommission;
  33.  
  34. profit_or_loss = stock(numShares, purchasePrice, purchaseCommission, salePrice, saleCommission);
  35. }
  36. }
  37. if (profit_or_loss < 0)
  38. {
  39. cout << "That is a loss of $ " << profit_or_loss << endl << endl;
  40. }
  41. else
  42. {
  43. cout << "That is a profit of $ " << profit_or_loss << endl << endl;
  44. }
  45. return 0;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement