|
-
November 13th, 2010, 11:39 PM
#1
C++ Loop problem
Here's what I have, but I'm having a problem because it's displaying a chart with employee id # and wage right after each employee instead of at the end.
Code:
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
const int NUM_EMPLOYEES = 7;
const int STRING_SIZE = 8;
int hours[NUM_EMPLOYEES];
int payRate[NUM_EMPLOYEES];
float wages[NUM_EMPLOYEES];
cout << "Enter the requested information for each employee. " << endl;
cout << endl;
for (int count = 0; count < NUM_EMPLOYEES; count++)
{
// Array with the 7 employee identification numbers.
char empId[NUM_EMPLOYEES][STRING_SIZE] =
{ "5658845", "4520125", "7895122", "8777541",
"8451277", "1302850", "7580489" };
cout << "Employee #" << empId[count] << endl;
cout << '\t' << "Hours worked: " << " ";
cin >> hours[count];
while( hours[count] < 0 ) // Hours worked must be at least 0.
{
// Error message.
cout << "Hours worked must be 0 or more. Please re-enter: " << " ";
cin >> hours[count];
}
cout << '\t' << "Pay rate: $" << " ";
cin >> payRate[count];
while( payRate[count] < 6 ) // Pay rate must be at least $6.
{
// Error message.
cout << "Pay rate must be $6.00 or more. Please re-enter: " << " ";
cin >> payRate[count];
}
{
wages[count] = hours[count] * payRate[count]; // Calculates employees wages.
cout << "----------------------------" << endl;
cout << "Employee" << '\t' << "Wages" << endl;
cout << "----------------------------" << endl;
cout << "Employee #" << empId[count] << " " << "$ " << wages[count] << endl;
}
}
return 0;
}
But I want it to display like this...
Employee #5658845
Hours worked: -1
Hours worked must be 0 or more. Please re-enter: 6
Pay rate: $5
Pay rate must be 6.00 or more. Please re-enter: $6
Employee #4520125
Hours worked: 7
Pay rate: $7
Employee #7895122
Hours worked: 8
Pay rate: $8
Employee #8777541
Hours worked: 9
Pay rate: $9
Employee #8451277
Hours worked: 10
Pay rate: $10
Employee #1302850
Hours worked: 11
Pay rate: $11
Employee #7580489
Hours worked: 12
Pay rate: $12
----------------------------
Employee Wages
----------------------------
Employee #5658845 $ 36.00
Employee #4520125 $ 49.00
Employee #7895122 $ 64.00
Employee #8777541 $ 81.00
Employee #8451277 $ 100.00
Employee #1302850 $ 121.00
Employee #7580489 $ 144.00
Press any key to continue . . .
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|