(Using MS Visual Basic 2008)
Hi, I have been ask to create a program that allows the user to input the hours worked and the payrate for a number of employees (note: Hours work and the payrate can all be differ, there is no set payrate), the number of employees should be determined by the user (i.e Prompt the user how many employees he/she want to process). The program will then calculate the weekly wages the employee(s) has earned (showing each employees wages, and display the result (weekly wages).
After all the employees weekly wages have been processed, the program should display a table that shows the
total normal hours worked by all employees, total overtime hours worked by all employees, total wages paid to all employees. Plz Help any info i will b thankful for :) Here Is What I Have So Far:

#include <iostream>
#include <typeinfo>
using namespace std;

int main()
{
	int hoursworked[], payrate[];
	float employees=0.0, hourscompleted=0.0;
	
	cout<<"Please Enter The Amount Of Numbers You Want To Process: ";
	cin>>employees;
	

for(int i=0;i<employees;i++)
{
	
	cout<<"Please Enter How Many Hours The Employee "<<(i+1)<<" Has Worked:";
	cin>>hoursworked[i];
	cout<<"Please Enter The Payrate Of Employee "<<(i+1)<<":";
	cin>>payrate[i];
	
	while(hoursworked[i]<0)//keep looping until a valid employee amount is entered
	{
		cout<<"Invalid Amount Of Employees Entered, Please Try Again";
		cin>>hoursworked[i];
}
}
}

Recommended Answers

All 6 Replies

im not askin 4 sum1 to do the work im asking 4 help, im having trouble in finding out how to read individual data for the arrays (hoursworked[], payrate[]; ) no where did it say sum1 do it 4 me, (LucyB If ure not gonna help dnt comment)
to every1 else help is needed not ANSWERS

Use code tags, dont just colour in your code green.

> int hoursworked[], payrate[]; What is this supposed to do? This does not make an array with an unlimited size if that's what you wanted.

You need to replace those arrays with dynamic ones as you dont know what size they are going to be (or you could use an std::vector). You also dont need the float data type for these arrays, they should be int. The code should look something more along the lines of:

#include <iostream>
#include <typeinfo>
using namespace std;

int main()
{
  int employees;
  float hourscompleted = 0.0f;

  cout << "Please Enter The Amount Of Numbers You Want To Process: ";
  cin >> employees;

  int *hoursworked = new int[employees],
      *payrate     = new int[employees];

  for (int i = 0; i < employees; i++) {
    cout << "Please Enter How Many Hours The Employee " << (i+1) << " Has Worked:";
    cin >> hoursworked[i];
    cout << "Please Enter The Payrate Of Employee " << (i+1) << ":";
    cin >> payrate[i];

    while ( hoursworked[i] < 0 )//keep looping until a valid employee amount is entered
    {
      cout << "Invalid Amount Of Employees Entered, Please Try Again";
      cin >> hoursworked[i];
    }
  }

  delete[] hoursworked, payrate;
}

Hope this helps.

Thank You For Replying williamhemsworth, i also need to be able to withdraw individaul information for employees, for example when you run the code you gave me; after you enter the number to be processed, then the hours they worked followed by the pay rate for the employee or employees, i need to be able to display pay which would be the employees wages seperatley.
for example if i was to enter
Test data:
hours worked employee 1: 10
pay rate: 5.5

hours worked employee 2: 40
pay rate: 10

I need to be able to produce something like this after:

Expected results test data set 1:
wages for employee 1: 55
wages for employee 2: 425

im not asking for calculations or nothing like that, just if you know how to extract that information to be displayed like that.
Thanks So Much Your Help :)

I realize I was wrong about the data type, they should in fact be float's, my mistake :icon_redface:

To display the wage for each employee, simply loop through each one, and print the value of both multiplied together.

#include <iostream>
#include <typeinfo>
using namespace std;

int main()
{
  int employees;

  cout << "Please Enter The Amount Of Numbers You Want To Process: ";
  cin >> employees;

  float *hoursworked = new float[employees];
  float *payrate = new float[employees];

  for (int i = 0; i < employees; i++) {
    cout << "\nPlease Enter How Many Hours The Employee " << (i+1) << " Has Worked: ";
    cin >> hoursworked[i];

    cout << "Please Enter The Payrate Of Employee " << (i+1) << ": ";
    cin >> payrate[i];

    while ( hoursworked[i] < 0 )//keep looping until a valid employee amount is entered
    {
      cout << "Invalid Amount Of Employees Entered, Please Try Again.\n";
      cin >> hoursworked[i];
    }
  }

  cout << "\n\n";

  for (int i = 0; i < employees; i++) {
    cout << "Wages for employee " << (i+1) << ": " << (hoursworked[i] * payrate[i]) << '\n';
  }

  delete[] hoursworked, payrate;

  cin.ignore();
  cin.ignore();
}

Hope this helps.

Thanks Again So Much It Worked Perfectly, You wouldnt believe the amount of research i looked into n then you just cum along, but thanks, would also be grateful if u could watch this space over the next few days thanks you best wishes

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.