hi all,

I need a little bit of help. heres my problem. if someone can help me get started, tht would be really wonderful. many thx in advance.

there are 7 different numbers are given which are emplyee identification number. The program should display each employee number and ask the user to enter that employee's hours and pay rate. The program should relate the data in each array through the subscripts. For example, the number in element 0 of the 'hours' array should be the number of hours worked by the employee whose identification number is stored in element 0 of the 'empId' array. That same employee's pay rate should be stored in element 0 of the payRate array.

i dont know how to display employee identification number since they are random numbers rathar than 1, 2, 3...

It may help to draw a picture of the data layout.

(index)            0       1      2      3       4       5       6

EmpID array   | 12345 | 93948 | 87654 | 34564 | 43210 | 000111 |   007   |

hours         |       |       |   12.0 |      |       |        |        |

rate          |       |       |   8.75 |      |       |        |        |

So, if an empID is given, look through the first array to find it. Its index then is used to store/get the hours worked and to store/get the rate of pay.

(darn that was hard to get the bars to line up!)
Val

ok, i get that. but i dont know how to use array function and index function to store it. can you give me an example using the command? thx for all the help

Starting simply:

int arr[10] = { 0 };  //declare array of size 10, set all elements to 0
int i;

for( i = 0; i < 10; i++ )
{
    cout << "enter employee ID> ";
    cin >> arr[i];          //as i increases, you move from element to element.
}

Note that the indexing starts at 0, and goes to one less than the size of array.

Val

Is it really necessary to write your application in C or C++?

- Perry

>Is it really necessary to write your application in C or C++?
It's probably an assignment for a C++ course, so yea, I imagine it's really necessary. Why do you ask?

hey vmanes,
thx for all the help. Let me show you my program which is currently working fine.

#include <iostream>
using namespace std;


int main ()
{
const int size = 7;
long empId = {5658845, 4520125, 7895122, 8777541,
8451277, 1302850, 7580489};
int array = { 5658845, 4520125, 7895122, 8777541,
8451277, 1302850, 7580489};
int hours;
float payRate, wages;
for (int count = 0; count < size; count++)
{
cout << "Employee number: " << array[count] <<endl;
cout << "# of hours worked: ";
cin >> hours[count];
cout << "Pay Rate: ";
cin >>payRate[count];
}
return 0;
}

IN THE END, I WANT TO ADD GROSS WAGES WHICH IS DETERMINED BY MULTIPLYING # OF HOURS WORKED AND PAY RATE. I HAVE TRIED DIFFERENT COMMANDS. BUT, DIDNT WORK. DO U HAVE ANY IDEA?

What have you tried? In what way didn't it work?

What you have gives you the main part of what you will need to compute pay.

If you had just a single value for payrate and for hours, how would you solve the problem? Once you can do that, then do it inside the loop, in terms of the array elements.

Why do you have two arrays with the same content: empID[] and array[] ?

Val

in order to calculate wages, i have tried following

for (int count = 0; count < size; count++)
{
wages = hours[count] * payRate[count];
cout << "Employee number: " << array[count] <<endl;
cout << ": $" << wages << endl;
}

>in order to calculate wages, i have tried following
I noticed that hours and payRate weren't ever initialized in your earlier code. If you don't ever put anything in those arrays, you're going to get garbage results across the board.

You declared wages as an array - do you intend to store each employee's pay there? If so, you need to access each element of wages in the pay loop as you access the elements for ID and payrate and hours.

I'd also delete the << endl at the end of the first output line in the pay loop. That way the ID and pay amount will be on the same line.

Pay attention to the error messages your compiler gives you. It would point you to the problem with wages in the loop.

V

i kind of get it, but not entirely though
can u write the code so i know wat i need to change? thanks

>can u write the code so i know wat i need to change?
If I write it for you then you wouldn't need to change anything anymore. ;) Here's a super huge hint though:

double payRate[size];
double hours[size];

// Fill in payRate and hours
for ( int i = 0; i < size; i++ ) {
  std::cout<<"Employee #"<< i <<" -- Hours: ";
  std::cin>> hours[i];

  std::cout<<"Pay Rate: ";
  std::cin>> payRate[i];
}

std::cout<<"\nCurrent wages:\n";

// Calculate wages
for ( int i = 0; i < size; i++ ) {
  std::cout<<"Employee #"<< i <<
    << payRate[i] * wages[i] <<'\n';
}

do i need to write double wages; ??

i still don't get it...:(

Your code:

for (int count = 0; count < size; count++)
{
     wages = hours[count] * payRate[count];
     cout << "Employee number: " << array[count] <<endl;
     cout << ": $" << wages << endl;
}

wages was declared as float wages[size]; , so it's an array. In your loop, you are not giving the index, which should correspond to each employee.

Just add the indexing [count] after each use of wages in the loop.

V

i know i have declared as a float wages;. so, i didnt get you when u said just add the indexing count after each use of wages in the loop.
you mean something like cin >> wages[count]; ??

No, I meant:

wages[count] = hours[count] * payRate[count];

i put that, and now i have stopped getting error. but now, i dont see wages being calculated in output, any idea? :(

#include <iostream>
using namespace std;

int main ()
{
    const int size = 7;
    int array[size] = { 5658845, 4520125, 7895122, 8777541,
                    8451277, 1302850, 7580489};
    int hours[size];
	float payRate[size], wages[size];
	cout << "Manthan Meghpara cs102 section 033241 online" <<endl;
	
	cout << " " << endl; //I am just skipping lines to match the exact output as you asked.
	cout << "Enter the info for each of the following" <<endl;
	cout << "employees identified by their ID numbers:" <<endl;
	
	cout << " " << endl; //I am just skipping lines to match the exact output as you asked.
	for (int count = 0; count < size; count++)
	{
       cout << "Employee number: " << array[count] <<endl;
       cout << "# of hours worked: ";
       cin >> hours[count];
       cout << "Pay Rate: ";
       cin >>payRate[count];
    }
    for (int count = 0; count < size; count++)
    {
        wages[count] = hours[count] * payRate[count];
        cout << "Employee number: " << array[count] <<endl;
        cout << ": $" << wages << endl;
    }
    system ("PAUSE");
    return 0;
}

Now look at the compiler error you get for:

cout << ": $" << wages << endl;]

Look familiar? You know how to fix it.

huh?

wages is an array
if you are going to output wages you have to specify which entry of wages you want to cout

you need an index

wages[index]

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.