Chapter 2 – Q #17 Stock Commission – Tony Gaddis – Starting Out With C++
Problem: -
- 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
- Declare two float constants shares and price and initialize given values.
- Declare three float constants for calculation.
- Calculate paid value without commission of product by multiplying price and shares.
- Calculate 2% commission.
- Calculate total paid value by adding paid and commission.
- In last, display output on the screen and use endl for new line.
- Return 0 to the main function.
Also, I attach CPP file of this problem. You can download this file
0 Comments