Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

"ERROR, Enter a Valid Hourly Rate" keeps on popping out, even if i enter a valid number..

+6 votes
asked Oct 10, 2021 by B03 Allen Balangue (180 points)
#include <iostream>

#include <iomanip>

using namespace std;

int main(){

start:

double hourlyRate = 0;

double overtimePay = 0;

double regularPay = 0;

double grossPay = 0;

int hoursWorked = 0;

double overtimeHours = 0;

double otperWeek = 0;

int employeeNo = 0;

char choice;

cout<<"Please Enter Employee Number: ";

while(!(cin>>employeeNo))

{

cout<<"ERROR, Enter a valid Employee Number: ";

cin.clear();

cin.ignore(100,'\n');

}

cout<<"Please enter Hours Worked for the Week: ";

while(!(cin>>hoursWorked))

{

cout<<"ERROR, Enter a valid Hours Worked for the Week: ";

cin.clear();

cin.ignore(100,'\n');

}

cout<<"Please enter hours of Over Time work for the week: ";

while(!(cin>>otperWeek))

{

cout<<"ERROR, Enter a valid hours of Over Time work for the week: ";

cin.clear();

cin.ignore(100,'\n');

}

cout<<"Please enter Hourly Rate:";

while(!(cin>>hourlyRate));

{

cout<<"ERROR, Enter a Valid Hourly Rate: ";

cin.clear();

cin.ignore(100,'\n');

}

if(hoursWorked>=40){

overtimeHours=hoursWorked+otperWeek-40;

hoursWorked=40;

overtimePay=overtimeHours*(1.5*hourlyRate);

}

    

    regularPay=hoursWorked*hourlyRate;

    

    grossPay=regularPay+overtimePay;

    

    cout<<"\nEmployee Number: "<<employeeNo<<endl;

    cout<<"Hours Worked: "<<(hoursWorked+overtimeHours)<<endl;

    cout<<"Hourly Rate: "<<hourlyRate<<endl;

    cout<<"Regular Pay: "<<regularPay<<endl;

    cout<<"Overtime Pay: "<<overtimePay<<endl;

    cout<<"Gross Pay: "<<grossPay<<endl;

    cout<<endl;

    

question:

   {

           cout<<"\nTry Another? [Y/N] :\n";

           cin>>choice;

            if (choice == 'y'|| choice == 'Y')

            {

                    goto start;

            }   

            if (choice == 'N' || choice == 'n')

{

    cout<<"\n\n\t-----------------------\n";

                    cout<<"\t  ALLEN JAMES BALANGUE";

                    cout<<"\n\t  SECTION: IT1A\n";

                    cout<<"\t-----------------------\n";

                    goto end;

}

            else

            {

                cout<<"\nINVALID INPUT"<<endl;

                goto question;

            }                  

    } while (choice == 'y'|| choice == 'Y' || choice == 'N' || choice == 'n');

    

end:

    system("pause");

    

}

1 Answer

0 votes
answered Oct 11, 2021 by Peter Minarik (84,720 points)
edited Oct 11, 2021 by Peter Minarik

You have an extra semicolon at the end of your while line, which makes the loop body empty. Remove it.

while(!(cin>>hourlyRate));

A note here: you should really not get into the habit of using the goto command. It makes the logic of the code hard to understand and follow. Use loops and functions instead.

Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...