#include <iostream> #include <cmath> using namespace std; void explanation(); void employeeType(int & vac, int & sick); int vacation( int vacationDays); int sick(int sickDays); void calculate(int usedVacation, int usedSick); int main() // The code is limited here to rely mainly on functions. { int vacationDays, sickDays, usedVacation, usedSick; char quit; do { explanation(); employeeType(vacationDays, sickDays); usedVacation = vacation(vacationDays); usedSick = sick(sickDays); calculate(usedVacation, usedSick); cout << "Would you like to quit? Selecting 'N' will repeat the program. <Y/N>: "; cin >> quit; cout << endl; } while(quit != 'y' || 'Y'); cout << "Press any key to terminate the program." << endl; cin.get(); cin.get(); return 0; }; void explanation() { cout << "This program serves to calculate the number of miles employees travel annually\nbased on three variables. It's Monday, January 1, 2007. As a new employee of\nWells Fargo, you only work weekdays and receive six federal holidays off.\nWith 255 working days in the year, you receive a differing number of vacation\nand sick days depending on whether you are a manager or a worker." << endl; cout << endl; } void employeeType(int & vac, int & sick) { char type; do { cout << "Are you a [M]anager or a [W]orker? "; cin >> type; if (type == 'm' || type == 'M') { vac = 20; sick = 10; break; } if (type == 'w' || type == 'W') { vac = 15; sick = 15; break; } else { cout << endl; cout << "That is not a valid entry. Please enter 'm', 'M', 'w', or 'W'." << endl; cout << endl; continue; } } while (type != 'm' || 'M' || 'w' || 'W'); cout << "You are allotted " << vac << " vacation days and " << sick << " sick days for the year." << endl; cout << endl; } int vacation(int vacationDays) { int ndays; do { cout << "Please enter the number of vacation days you plan to use: "; cin >> ndays; if (ndays > vacationDays || ndays < 0) { cout << endl; cout << "You must enter a valid number within the range of allotted vacation days." << endl; } else { cout << endl; return ndays; } }while(ndays > vacationDays || ndays < 0); } int sick(int sickDays) { int ndays; do { cout << "Please enter the number of sick days you plan to use: "; cin >> ndays; if (ndays > sickDays || ndays < 0) { cout << "You must enter a valid number within the range of allotted sick days." << endl; cout << endl; } else { cout << endl; return ndays; } }while(ndays > sickDays || ndays < 0); } void calculate(int usedVacation, int usedSick) { int daysWork = (255 - usedVacation - usedSick); // Calculates the number of days worked by subtracting the number of claimed vacation and sick days from the total working days. int milesTraveled = daysWork * 530; // Each workday is multipled by a value of 530 miles to account for the daily commute back-and-forth between CityA and CityB. cout << "Based on your input, you plan to work " << daysWork << " days this year. Each workday, you\nwill commute 265 miles to and from work for a total of 530 miles. Multiplying\n530 miles by " << daysWork << " workdays, it is estimated that you will travel a total\nof " << milesTraveled << " miles this year. I hope you have a comfortable, properly-insured car!" << endl; cout << endl; }
Any thoughts? I just want the program to break from the loop and exit when the user enters 'quit' as 'y' or 'Y'. Any help would be appreciated!