Deitel C++ How To Program 9th Edition Chapter 4 Exercise 4.15

13 Jul 2024 - Syed Muhammad Shahrukh Hussain

Write a program which calculates salesman commission. The salesman commission is 9% of the sales, and his gross pay is 200.

Terminal

Enter sales[-1 to exit]:100
Salesman commission:$209.00

Solution

#include <iostream>
#include <iomanip>

using namespace std;

#define COMMISSION  9/100
#define SALEMAN_PAY 200

int main() {
  double sales = -1;
  double total = 0;

  cout << "Enter sales[-1 to exit]:";
  cin >> sales;
  while(sales != -1) {
    total = SALEMAN_PAY + sales * COMMISSION;
    cout << "Salesman commission:"<< "$" << fixed << setprecision(2) <<  total << endl;
    cout << "Enter sales[-1 to exit]:";
    cin >> sales;
  }
  return  0;
}

Sources