Actually, there may be an even better way to design the function because it's more "self-documenting":
Code:studio = getData("studio"); oneBed = getData("one-bedroom"); twoBed = getData("two-bedroom");Again we could have used a const char* rather than a std::string const reference, but in this case it isn't *quite* the same-----this way allows you to pass either a char* in or a string object.Code:int getData(const std::string &apttype) { int num; cout << "How many " << apttype << " apartments?: "; cin >> num; return num; }




Reply With Quote