// Bjarne Stroustrup 1/15/2010 // Chapter 6 Exercise 9 /* Compose integers out of characters: 123 is 1 hundered 2 tens and 3 ones */ #include "std_lib_facilities.h" int main() try { vector digit; // collect digits here vector unit; // unit names go here unit.push_back(" ones "); unit.push_back(" tens "); unit.push_back(" hundreds ");; unit.push_back(" thousands "); unit.push_back(" tens of thousands "); unit.push_back(" hundreds of thousands "); unit.push_back(" millions "); unit.push_back(" tens of millions "); unit.push_back(" hundreds of millions "); /* note that the size of the unit vector is used to determine how many digits we can handle. Not magic constant has been introduced. */ /* The exercise didn't specify how to terminate a number, so we have to decide. */ cout << "Please enter an integer with no more than " << unit.size() << "\ndigits followed by semicolon and a newline: "; char ch; while (cin>>ch) { // remember cin>>ch skips whitespace (this could be simpler written using cin.get(ch) ) if (ch<'0' || '9'