• Source
    1. #include <iostream>
    2.  
    3. using namespace std;
    4.  
    5. //define constant
    6. const double SERVICE_FEE = 0.015;
    7.  
    8. int main()
    9. {
    10.  
    11. //declaring my variables
    12. double sharesSold;
    13. double purchasePrice;
    14. double sellingPrice;
    15. double amntInvested;
    16. double amntRecieved;
    17. double gainLost;
    18. double totalService;
    19. double buyService;
    20. double sellService;
    21.  
    22. //asking for user input
    23. cout << "How many shares did you sell?: ";
    24. cin >> sharesSold;
    25.  
    26. cout << "What was the purchase price of each share?: $";
    27. cin >> purchasePrice;
    28.  
    29. cout << "What was the selling price of each share?: $";
    30. cin >> sellingPrice;
    31.  
    32. //start entering formulas to calculate service fees
    33. sellService = (sharesSold * sellingPrice) * SERVICE_FEE;
    34. buyService = (sharesSold * purchasePrice) * SERVICE_FEE;
    35. totalService = (buyService + sellService);
    36.  
    37. //enter formulas to calculate total invested amount
    38. amntInvested = (purchasePrice * sharesSold) + buyService;
    39.  
    40. //display outputs so far
    41. cout << "The total amount you invested is: $" << amntInvested << endl;
    42. cout << "The total amount of Service Charges is: $" << totalService << endl;
    43.  
    44. //calculate how much is gained or lost
    45. gainLost = (sharesSold * (sellingPrice - purchasePrice)) - totalService;
    46.  
    47. if (gainLost > 0)
    48. cout << "Total Amount Gained: $" << gainLost << endl;
    49. else
    50. cout <<"Total Amount Lost: $" << (gainLost*-1) << endl;
    51. //calculate recieved amnt
    52. amntRecieved = (sharesSold * sellingPrice) - sellService;
    53.  
    54. cout << "The total amount you recieved is: $" << amntRecieved << endl;
    55.  
    56. return 0;
    57.  
    58. }
    59.