Hello, I'm a beginner in this site. I was just hoping that someone might be able to answer my question regarding to debugging a payroll.

Here:

#include <iostream>
#include <conio.h>
#include <string>
#include <windows.h>
#include <stdio.h>

using namespace std;

const string userName= "Username";    //assigns the username
const string passWord= "Password";    //assigns the password

int main()
{
    cout << "\n\t\t  Welcome To Your Payroll Account!" <<endl;
    cout << "\t\t  Please Enter Your Username & Password To Proceed.  " <<endl;
    cout << "\t *********************************************************" <<endl;

    string pass[10];
    string name;
    string month,Ename,address;
    float regpay, regov, RD, RDOT, meal;
    float SSS, PH, PI, Union, other, SSSsal, Loan, Hloan, ULoan, ELoan, TD;
    float TE,Netpay;
    int n,day,year;
    char input;

    char again = 'Y';
    while (again =='Y' || again =='y')       //creates the loop for test condition
    {
        cout << "\nUsername: ";    //prompt user
        cin  >> name;          //inputs name
        cout << "Password: ";      //prompt user
        for(int i=1;i<10;i++)
        {
            pass[i]=_getch();
            cout<<"*";
            passWord == pass[i]; 
        }

        if (name == userName && passWord == passWord)    // Executes the statements if condition is TRUE 
        cout << "\n \n You are logged in!"
             << "\n Enter '#' to proceed: ";   //Output if the condition is TRUE  

        else  // Executes the statements if another condition is TRUE or FALSE

        cout << "\n Incorrect username or password. \a" 
             << "\n \n Do you want to try again? Yes(Y)/No(N) "
             << "\n \n Continue? "; // prompt user
        cin >> again;  // inputs looping
    }
    while (again == 'y' || again == 'Y')
    {
        if(again == 'N' || again == 'N');
        goto stop;
    }

    {
        {
            cout<<"\n Enter '#' again to Proceed to your Payslip: "; 
            cin>>input;
            if (input == '#');
            {
                cout <<" " <<endl;
                cout << "\nMonth: " ;
                cin  >> month;
                cout << "Day: ";
                cin  >> day;
                cout << "Year: ";
                cin  >> year;
                cout << "\n\n EMPLOYEE'S NAME: ";
                cin  >> Ename;
                cout << "EMPLOYEE'S ADDRESS: ";// Starting at this point the program terminates and giving negative values result on the payroll.
                cin  >> address;
                cout << "REGULAR PAY: ";
                cin  >> regpay;
                cout << "REST DAY: ";
                cin  >>RD;
                cout << "REGULAR OVERTIME: ";
                cin  >> regov;
                cout << "RESTDAY OT: ";
                cin  >> RDOT;
                cout << "MEAL ALLOWANCE:";
                cin  >> meal;
                cout <<"SSS: ";
                cin  >>SSS;
                cout << "PhilHealth: ";
                cin  >>PH;
                cout << "PAG-IBIG: ";
                cin >>PI;
                cout << "Union Dues: ";
                cin >>Union;
                cout << "Other Deductions: ";
                cin >>other;

                cout << "\n\t\t\t    Nutri Snack Food Corp." <<endl;
                cout << "\n\t\t\t Gen. Luis St. Novaliches, Q.C." <<endl;
                cout << "\n\t*************************************************************** " << endl;
                cout << "\n\t\t\t Payslip for: " <<month <<"-" <<day <<"-" <<year <<endl;
                cout << "\n\t*************************************************************** " << endl;
                cout << "\n\t Name: " <<Ename <<endl;
                cout << "\t Address: " <<address <<endl;
                cout << "\n ======== EARNINGS ========" << "\t\t\t ======== DEDUCTIONS =======" <<endl;
                cout << "   Regular Pay = " <<regpay << "\t\t\t\t   SSS = " <<SSS <<endl;
                cout << "   Regular OT = " <<regov << "\t\t\t\t   PhilHealth = " <<PH <<endl;
                cout << "   Rest Day = " <<RD << "\t\t\t\t   PAG-IBIG = " << PI <<endl;
                cout << "   Rest Day OT = " <<RDOT << "\t\t\t\t   Union Dues: " << Union <<endl;
                cout << "   Meal Allowance = " <<meal << "\t\t\t\t   Other Deductions: " <<other <<endl;


                TD =(SSS+PH+PI+Union+other);
                TE = (regpay+regov+RD+RDOT+meal);
                Netpay = TE-TD;

                cout << "\n\t\t ===========================================" <<endl;
                cout << "\t\t TOTAL DEDUCTION: " << TD << " TOTAL EARNINGS: " <<TE <<endl;
                cout << "\t\t ===========================================" <<endl;
                cout << "\t\t\t\t NETPAY: " <<Netpay <<endl;

                stop:
                _getch();
                system ("pause");
                return 0;

                }
        }
    }
}

I was thinking that the formula given as already right but it keeps on terminating the wrong way. I appreciate suggestions in helping to debug this.

Ok, I will try using getline starting on the EMPLOYEE ADDRESS. Hope it works.

Solved! I'm gonna share this so the others whose having the same problem as mine can have their reference! TT ^ TT

#include <iostream>
#include <conio.h>
#include <string>
#include <windows.h>
#include <stdio.h>

using namespace std;

const string userName= "Otani";    //assigns the username
const string passWord= "Atsushi";    //assigns the password

int main()
{
    cout << "\n\t\t  Welcome To Your Payroll Account!" <<endl;
    cout << "Please Enter Your Username & Password To Proceed (Screen name is accepted for confidentiality)" <<endl;
    cout << "\t \t **********************************************************" <<endl;

    string pass[10];
    string name;
    string Ename;
    string month;
    string address;
    float regpay, regov, RD, RDOT, meal;
    float SSS, PH, PI, Union, other, SSSsal, Loan, Hloan, ULoan, ELoan, TD;
    float TE,Netpay;
    int n,day,year;
    char input;

    char again = 'Y';
    while (again =='Y' || again =='y')       //creates the loop for test condition
    {
        cout << "\nUsername: ";    //prompt user
        cin  >> name;          //inputs name
        cout << "Password: ";      //prompt user
        for(int i=1;i<10;i++)
        {
            pass[i]=_getch();
            cout<<"*";
            passWord == pass[i]; 
        }

        if (name == userName && passWord == passWord)    // Executes the statements if condition is TRUE //****** passWord = passWord na kasi yung value ng pass[i] nakay passWord na.
        cout << "\n \n You are logged in!"
             << "\n Enter '#' to proceed:";   //Output if the condition is TRUE  

        else  // Executes the statements if another condition is TRUE or FALSE

        cout << "\n Incorrect username or password. \a" 
             << "\n \n Do you want to try again? Yes(Y)/No(N) "
             << "\n \n Continue? "; // prompt user
        cin >> again;  // inputs looping
    }
    while (again == 'y' || again == 'Y')
    {
        if(again == 'N' || again == 'N');
        goto stop;
    }

    {
        {
            cout<<"\n Enter '#' again to Proceed to your Payslip: "; //Ginawa ko na lang to para mabigyan ng value yung input para magamit sa if-statement. (And para di na pampalito :D )
            cin>>input;
            if (input == '#');
            {
                cout <<" " <<endl;
                cout << "\nMonth: ";
                cin  >> month;
                cout << "\nDay: ";
                cin  >> day;
                cout << "\nYear:";
                cin  >> year;
                cin.ignore();//Used so that the getline won't skip.
                cout << "\nEMPLOYEE'S NAME:";
                getline(cin,Ename);//Used to be able to receive as many lines as you want with the space variable included.
                cout << "\nEMPLOYEE'S ADDRESS:";
                getline(cin,address);
                cout << "\nREGULAR PAY:";
                cin  >> regpay;
                cout << "\nREST DAY:";
                cin  >>RD;
                cout << "\nREGULAR OVERTIME:";
                cin  >> regov;
                cout << "\nRESTDAY OT:";
                cin  >> RDOT;
                cout << "\nMEAL ALLOWANCE:";
                cin  >> meal;
                cout <<"\nSSS:";
                cin  >>SSS;
                cout << "\nPhilHealth: ";
                cin  >>PH;
                cout << "\nPAG-IBIG:";
                cin >>PI;
                cout << "\nUnion Dues:";
                cin >>Union;
                cout << "\nOther Deductions:";
                cin >>other;

                TD =(SSS+PH+PI+Union+other);//Total Deduction
                TE = (regpay+regov+RD+RDOT+meal);// Total Earnings
                Netpay = TE-TD;//Net Salary


                cout << "\n\t\t\t    Nutri Snack Food Corp." <<endl;
                cout << "\n\t\t\t Gen. Luis St. Novaliches, Q.C." <<endl;
                cout << "\n\t*************************************************************** " << endl;
                cout << "\n\t\t\t Payslip for: " <<month <<"-" <<day <<"-" <<year <<endl;
                cout << "\n\t*************************************************************** " << endl;
                cout << "\n\t Name: " <<Ename <<endl;
                cout << "\t Address: " <<address <<endl;
                cout << "\n ======== EARNINGS ========" << "\t\t\t ======== DEDUCTIONS =======" <<endl;
                cout << "   Regular Pay = " <<regpay << "\t\t\t\t   SSS = " <<SSS <<endl;
                cout << "   Regular OT = " <<regov << "\t\t\t\t   PhilHealth = " <<PH <<endl;
                cout << "   Rest Day = " <<RD << "\t\t\t\t   PAG-IBIG = " << PI <<endl;
                cout << "   Rest Day OT = " <<RDOT << "\t\t\t\t   Union Dues: " << Union <<endl;
                cout << "   Meal Allowance = " <<meal << "\t\t\t\t   Other Deductions: " <<other <<endl;



                cout << "\n\t\t ===========================================" <<endl;
                cout << "\t\t TOTAL DEDUCTION: " << TD << " TOTAL EARNINGS: " <<TE <<endl;
                cout << "\t\t ===========================================" <<endl;
                cout << "\t\t\t\t NETPAY: " <<Netpay <<endl;

                stop:
                _getch();
                system ("pause");
                return 0;
            }
        }
    }
}

So now the code can compute the NetPay without problems. The getline(cin,___) and the cin.ignore(); works like freatly in this code. Hope this helps XD

This article has been dead for over six months. Start a new discussion instead.