So, Ive been reading on this topic and it seems to have been mentioned before but I am still having errors appear with my program. The assignment is:
Write a program that uses the following arrays:
• empId: an array of seven long integers to hold employee identification numbers.
The array should be initialized with the following numbers:
5658845 4520125 7895122 8777541
8451277 1302850 7580489
• hours: an array of seven integers to hold the number of hours worked by each
employee
• payRate: an array of seven doubles to hold each employee’s hourly pay rate
• wages: an array of seven doubles to hold each employee’s gross wages
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.
The program should display each employee number and ask the user to enter that
employee’s hours and pay rate. It should then calculate the gross wages for that
employee (hours times pay rate) and store them in the wages array. After the data has been entered for all the employees, the program should display each employee’s identification number and gross wages.
Input Validation: Do not accept negative values for hours or numbers less than 6.00
for pay rate.
Gaddis, Tony (2011-09-15). Starting Out with C++: From Control Structures through Objects, Brief Edition (7th Edition) (Page 445). Addison-Wesley. Kindle Edition.
My code is as follows, and it seems like an easy fix however I am getting an error at line 63 stating "expecting '}' At the end of input", but there is a bracket there. Is there something that I am missing?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
|
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
using namespace std;
int main()
{
const int empId = 7;
int workers[empId] = {5658846, 4520125, 7895122,
8777541, 8451277, 1302850,
7580489};
int hours[empId];
double payRate[empId];
\
cout << "Please enter the hours worked by " << empId
<< " employees and their\n"
<< "hourly pay rates.\n";
for (int index = 0; index < empId; index++)
{
cout << "Please enter the hours worked by employee number " << (index+1) << " (ID = " << workers[index] << ") : ";
cin >> hours[index];
cout << "Please enter the pay rate for employee number "<< (index+1) << " (ID = " << workers[index] << ") : ";
cin >> payRate[index];
do
{
cout << "Please enter the hours worked by employee number " << (index+1) << " (ID = " << workers[index] << ") : ";
cin >> hours[index];
if(hours[index] < 0)
{
cout << "Enter in a positive number" << endl;
}
}
while(hours[index] < 0);
do
{
cout << "Please enter the pay rate for employee number "<< (index+1) << " (ID = " << workers[index] << ") : ";
cin >> payRate[index];
if(payRate[index] < 6)
{
cout << "The pay rate must be >= 6" << endl;
}
}
while(hours[index] < 6);
cout << "This is the gross pay for each employee:\n";
cout << fixed << showpoint << setprecision(2);
for (int index = 0; index < empId; index++)
{
double grossPay = hours[index] * payRate[index];
cout << "Employee #" << (index + 1);
cout << ": earned $" << grossPay << endl << endl;
{
return 0;
}
|