Chapter 2 – Q #17 Stock Commission – Tony Gaddis – Starting Out With C++

Chapter 2 – Q #17   Stock Commission – Tony Gaddis – Starting Out With C++



Chapter 2 – Q #17   Stock Commission – Tony Gaddis – Starting Out With C++

Problem: - 

Kathryn bought 600 shares of stock at a price of $21.77 per share. She must pay her stock broker a 2 percent commission for the transaction. Write a program that calculates and displays the following:

  • The amount paid for the stock alone (without the commission)
  • The amount of the commission
  • The total amount paid (for the stock plus the commission)

Solution: -

#include <iostream>

using namespace std;

int main()

{

      const float shares = 600,

                  price = 21.77;

      float commission = 0.0, paid_wc = 0.0, total_paid = 0.0;

      paid_wc = price * shares;

      commission = (2 / 100.0) * paid_wc;

      total_paid = paid_wc + commission;

      cout << "Total Price Without Commission is $" << paid_wc << endl;

      cout << "Total Commission is               $" << commission << endl;

      cout << "Total Price With Commission is    $" << total_paid << endl;

     return 0;

}


This is the solution of this question




OUTPUT OF THIS QUESTION


Explanation of this Solution


  1. Declare two float constants shares and price and initialize given values.
  2. Declare three float constants for calculation.
  3. Calculate paid value without commission of product by multiplying price and shares.
  4. Calculate 2% commission.
  5. Calculate total paid value by adding paid and commission.
  6.  In last, display output on the screen and use endl for new line.
  7. Return 0 to the main function.

Also, I attach CPP file of this problem. You can download this file

Click Here to Download This File




Thanks!  



Post a Comment

0 Comments