// Program file: demoBoolean.cpp // Demos the use of the bool data type #include #include bool isAnAdult(int a); bool isASmoker(char s); void getData(char n[], int &a, char &s); void writeData(char n[], bool a, bool s); using namespace std; int main() { char name[11]; int age; char smoker; bool isOver21, isSmoker; char done = 'N'; while (done != 'Y' && done != 'y') { clrscr(); getData(name, age, smoker); isOver21 = isAnAdult(age); isSmoker = isASmoker(smoker); writeData(name, isOver21, isSmoker); cout << "Done entering data (Y/N): "; cin >> done; } cout << "End of program . . ."; getch(); return 0; } bool isAnAdult(int a) { if (a >= 21) return true; else return false; } bool isASmoker(char s) { if (s == 'Y' || s == 'y') return true; else return false; } void getData(char n[], int &a, char &s) { cout << "Enter a name: "; cin >> n; cout << "Enter an age: "; cin >> a; cout << "Enter 'Y/N' for smoker: "; cin >> s; } void writeData(char n[], bool a, bool s) { int count = 0; cout << "The name is " << n << endl; if (a) cout << n << " is 21 or over" << endl; else cout << n << " is under 21" << endl; cout << n << " is a smoker? " << s << endl; count = a + s; cout << "Age + Smoker is " << count << endl; }