Intro to programming

Last Edited By Krjb Donovan
Last Updated: Mar 12, 2014 02:46 PM GMT


I tried to write a code for this program but I have no luck to run it. I need you to help me. Develop a C++ program that uses a while statement to determine the gross pay for each of several employees. The company pays "straight time" for the first 40 hours worked by each employee and pays "time-and-a-half" for all hours worked in excess of 40 hours. you are given a list of the employees of the company, the number of hours each employee worked last week and the hourly rate of each employee. Your program should input this information for each employee and should determine and display the employee's gross pay. The gross pay should be printed as a floating-point value and with two digits of precision to the right of the decimal point.

Enter hours worked(-1 to end):39 Enter hourly rate of the worker(R00.00):10.00 Salary is R390.00 Enter hours worked(-1 to end):40 Enter hourly rate of the worker(R0.00):10.00 Salary is R400.00 Enter hours worked(-1 to end):41 Enter hourly rate of the worker(R00.00) Salary is R415.00 Enter hours worked(-1 to end):-1


Hello Mayibongwe

I would have liked to see your code, even if it didn't run. It would help me to help you learn. Anyway, I'll help you by starting you off. I'll show you how to do the input from the keyboard into variables, then you can use the variables in the salary calculation.

To do input and output in C++, you need to include the iostream header file, and use the iostream objects cin for input, and cout for output.

Below is the start of the code. You need to add the loop and the calculation.

Good luck, show me your attempt if you want more help

Kindest regards Zlatko

  1. include <iostream>

using namespace std;

int main(void) {

   double hours;
   double payRate;
   double salary;
   // TODO, put the code below into a loop
   cout << "Enter hours worked(-1 to end):";
   cin >> hours;
   if (hours > 0)
       cout << "Enter hourly rate of the worker(R00.00):";
       cin >> payRate;

       /* TODO calculate salary here based on the hours worked.
          There are 2 cases, one where hours > 40, 
          and one where the hours are <= 40
        cout << "Salary is R" << salary << endl;



One large chemical company pays its salespeople on a commission basis. The saleseople each receive R200 per week plus 9 percent of their gross sales for that week. For example, a salesperson who sells R5000 worth of chemicals in a week receives R200 plus 9 percent of R5000, or a total of R650. Develop a c++ program that uses a while statement to input each salesperson's gross sales for last week and calculates and displays that salesperson's earnings. process one salesperson's figures at a time.

The salesperson's earnings should be printed as a fixed-point value with a decimal point and with two digits of precision to the right of the decimal point.


See if this code works out your problem:-

  1. include<iostream.h>
  2. include<stdio.h>
  3. include<conio.h>
  4. include<iomanip.h>
  5. include<process.h>

int main() { float sales,earn; char ch; while(1) { cout<<"\nEnter the salesman's sales->"; cin>>sales; cout<<setprecision(6); earn=200+0.09*sales; cout<<"\nHis earning is::"; cout<<earn; cout<<"\nWant to continue?(Press Y or N)->"; fflush(stdin); ch=getche(); if(ch=='N'||ch=='n') { cout<<"\n*********THANK YOU********\n"; exit(1); } } return 0; }


©2022 eLuminary LLC. All rights reserved.