ChrisVig
ChrisVig

Reputation: 27

Keep getting 2 errors when trying to compile and run this program I need for class

Can someone help with this code, I keep getting these two errors [Error] expected unqualified-id before 'while' and [Error] expected declaration before '}' token. Coding is not my strong suit and I'm trying to get this assignment done yet my inexperience seems to be showing. Someone tried to explain to me but something with coding doesn't make sense sometimes. Anyone that can maybe help would be greatly appreciated.


#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iomanip>

using namespace std;
void GetData (string & fullName, int &idNum, float &workHours,
          float &hourlyRate);
void computePay (float &workHours, float &hourlyRate, float &grossPay);
void printReport (string fullName, int idNum, float workHours,
          float hourlyRate, float grossPay);

char another;
int idNum;
string name;
float rate;
float hoursWorked;
float grossPay;

int
main ()
{
  GetData (name, idNum, hoursWorked, rate);
  computePay (hoursWorked, rate, grossPay);
  printReport (name, idNum, rate, hoursWorked, grossPay);

  cout << "Would you like to enter in another employee (y/n)? \t ";
  cin >> another;
}
while (another != 'n');

}


void
GetData (string & name, int &idNum, float &hoursWorked, float &rate)
{
  cout << "Please enter your first and last name separated by a space:\t";
  getline (cin, name);
  cout << "Please enter the four digit employee I.D. number:\t";
  cin >> idNum;
  cout << "Please enter the hours worked:\t";
  cin >> hoursWorked;
  cout << "Please enter the hourly rate of pay:\t";
  cin >> rate;
}

void
computePay (float &hoursWorked, float &rate, float &grossPay)
{
  if (hoursWorked <= 40)
    {
      grossPay = hoursWorked * rate;
    }

  else if (hoursWorked <= 60)
    {
      grossPay = (rate * 40) + (hoursWorked - 40) * 1.5 * rate;
    }

  else
    {
      grossPay = (rate * 40) + (30 * rate) + (hoursWorked - 60) * 2.0 * rate;
    }
}

void
printReport (string name, int iD, float hoursWorked, float rate,
         float grossPay)
{
  cout << "Employee Name:\t" << name << endl;
  cout << "Employee I.D:\t" << setw (4) << setfill ('0') << idNum << endl;
  cout << "Hours worked:\t" << hoursWorked << endl;
  cout << "Hourly rate:\t" << rate << endl << endl;
  cout.precision (2);
  cout << "Gross Pay:\t$" << grossPay << endl << endl;
}

Upvotes: 0

Views: 31

Answers (1)

Soundararajan
Soundararajan

Reputation: 2194

Here is the answer. You were missing a do statement for the corresponding while statement.

#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iomanip>

using namespace std;
void GetData (string & fullName, int &idNum, float &workHours,
          float &hourlyRate);
void computePay (float &workHours, float &hourlyRate, float &grossPay);
void printReport (string fullName, int idNum, float workHours,
          float hourlyRate, float grossPay);

char another;
int idNum;
string name;
float rate;
float hoursWorked;
float grossPay;

int
main ()
{
do
{
  GetData (name, idNum, hoursWorked, rate);
  computePay (hoursWorked, rate, grossPay);
  printReport (name, idNum, rate, hoursWorked, grossPay);

  cout << "Would you like to enter in another employee (y/n)? \t ";
  cin >> another;
}
while (another != 'n');

}


void
GetData (string & name, int &idNum, float &hoursWorked, float &rate)
{
  cout << "Please enter your first and last name separated by a space:\t";
  getline (cin, name);
  cout << "Please enter the four digit employee I.D. number:\t";
  cin >> idNum;
  cout << "Please enter the hours worked:\t";
  cin >> hoursWorked;
  cout << "Please enter the hourly rate of pay:\t";
  cin >> rate;
}

void
computePay (float &hoursWorked, float &rate, float &grossPay)
{
  if (hoursWorked <= 40)
    {
      grossPay = hoursWorked * rate;
    }

  else if (hoursWorked <= 60)
    {
      grossPay = (rate * 40) + (hoursWorked - 40) * 1.5 * rate;
    }

  else
    {
      grossPay = (rate * 40) + (30 * rate) + (hoursWorked - 60) * 2.0 * rate;
    }
}

void
printReport (string name, int iD, float hoursWorked, float rate,
         float grossPay)
{
  cout << "Employee Name:\t" << name << endl;
  cout << "Employee I.D:\t" << setw (4) << setfill ('0') << idNum << endl;
  cout << "Hours worked:\t" << hoursWorked << endl;
  cout << "Hourly rate:\t" << rate << endl << endl;
  cout.precision (2);
  cout << "Gross Pay:\t$" << grossPay << endl << endl;
}

Upvotes: 1

Related Questions