lundi 8 juin 2015

Compare strings using ==

Below code is compiling well, but it always says "Invalid Employee id" even when I enter the correct employee id, Please someone tell me why and how to do this correctly.

#include <iostream>
#include <iomanip>
using namespace std;
char select, js;
char empid[4];
double bSalary, bonus, tot=0.0;
int main()
{
    do
    {
        cout<<"Employee id: ";
        cin>>empid;
        if(empid=="M001" || empid=="A004" || empid == "M002") //these are employee ids
        {   
            cout<<"Job Status: ";
            cin>>js;
            if(js=='P' || js=='C')
            {
                cout<<"Basic Salary: ";
                cin>>bSalary;
                if(bSalary>75000 && js=='P')
                {
                    bonus = bSalary*(20.0/100.0);
                    tot = tot + bonus + bSalary;
                }
                else if(bSalary>75000 && js=='C')
                {
                    bonus = bSalary*(15.0/100.0);
                    tot = tot + bonus + bSalary;
                }
                else
                    tot = tot+bonus+bSalary;
            }
            else
                cout<<"Invalid Job Status"<<endl;
        }
        else
            cout<<"Invalid Employee no"<<endl;
        cout<<"Do you want to continue: ";
        cin>>select;
        cout<<endl;
    }while(select=='y'||select=='Y');
    cout<<"Total cost: "<<setprecision(2)<<setiosflags(ios::fixed)<<tot<<endl;
    return 0;
}

it seems it working only else part only, How to run it correctly?

Aucun commentaire:

Enregistrer un commentaire