/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */ /* * 10.c * Copyright (C) Jason Thigpen 2007 * * 10.cpp is free software. * * You may redistribute it and/or modify it under the terms of the * GNU General Public License, as published by the Free Software * Foundation; either version 2 of the License, or (at your option) * any later version. * * main.cpp is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with 10.cpp. If not, write to: * The Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301, USA. */ /* * * Jason Thigpen * This program attempts to calculate an employee's pay * COP2220 * */ #include #include #include using namespace std; int main(int argc, char *argv[]) { char name[25]; //char name; float pay = 0.00, payOT = 0.00, payReg = 0.00; int rate = 0, hours = 0, overTime = 0; const float OT_RATE = 1.50; system("clear"); // system("cls"); cout << "\n\n\tWhat is your name?\n\t"; cin.getline(name,25); cout << "\n\n\tWhat is your hourly rate of pay? ( $ / hour )\n\t$"; cin >> rate; cout << "\n\n\tHow many hours did you work this week?\n\t"; cin >> hours; system("clear"); // system("cls"); if (( hours > 0 && hours <= 168 ) && ( rate > 0 && rate <= 100 )) { if ( hours > 40 ) { cout << "\n\n\t\t\tGood for you! :)\n\t\t\tYou you earned extra\n\t\t\tfor the hours you worked\n\t\t\tover 40\n"; overTime = hours - 40; payOT = overTime * ( rate * OT_RATE ); payReg = rate * 40; pay = payReg + payOT; cout << "\n\t\t" << name << "'s Pay Summary"; cout << "\n\t\t============================"; cout << fixed << setprecision(2); cout << "\n\t\tHours Worked : " << setw(8) << hours; cout << "\n\t\tRate of Pay : $" << setw(8) << rate << "/hour"; cout << "\n\t\tRegular Pay : $" << setw(8) << payReg; cout << "\n\t\tOvertime Pay : $" << setw(8) << payOT; cout << "\n\t\tTotal Pay : $" << setw(8) << pay; cout << "\n\n\n"; } else { cout << "\n\n\t\t\tToo bad :(\t\t\n\t\t\tNo over-time\n\t\t\tpay for you\n"; pay = ( rate * hours ); cout << "\n\t\t" << name << "'s Pay Summary"; cout << "\n\t\t============================"; cout << fixed << setprecision(2); cout << "\n\t\tHours Worked : " << setw(8) << hours; cout << "\n\t\tRate of Pay : $" << setw(8) << rate << "/hour"; cout << "\n\t\tRegular Pay : $" << setw(8) << pay; cout << "\n\t\tOvertime Pay : $" << setw(8) << payOT; cout << "\n\t\tTotal Pay : $" << setw(8) << pay; cout << "\n\n\n"; } } else if (( hours > 168 || hours <= 0 ) && ( rate > 100 || rate <= 0)) cout << "\n\n\t\tYou really don't want me to help\n\t\tdo you?\n\n\n"; else /*if (( hours > 168 || hours <= 0 ) || ( rate > 100 || rate <= 0))*/ { if ( hours > 168 || hours <= 0 ) { if ( hours > 168 ) cout << "\n\n\t\tSorry " << name << "\n\t\tThere are only 168 hours in a week =P \n\n\n"; else if ( hours == 0 ) cout << "\n\n\t\tIf you didn't work at all\n\t\twhy are you trying to calculate \n\t\tyour pay " << name << "?\n\n\n"; else cout << "\n\n\t\tError!\n\n\t\tYou entered a negative number\n\t\tfor the amount of hours you worked\n\t\tDo you want to pay me for the hours you didn't work?\n\n\n"; } else if ( rate > 100 || rate <= 0 ) { if ( rate > 100 ) cout << "\n\n\t\tCome on " << name << "\n\t\tI know we don't pay you that much\n\n\n"; else if ( rate == 0 ) cout << "\n\n\t\tIf you're working for free\n\t\twhy are you trying to calculate \n\t\tyour pay " << name << "?\n\n\n"; else cout << "\n\n\t\tError!\n\n\t\tYou entered a negative number\n\t\tfor your hourly rate\n\t\tDo you want to pay me for the hours you worked?\n\n\n"; } } return 0; }