void Print_List(Student* List, int Size) { // you don't need the &
// Create a Lambda function to simplify things
auto printDashes = [](const std::string& id) {
std::ostringstream out;
// loop over each character in the string
for (std::string::const_iterator it = id.begin(); it != id.end(); ++it) {
switch (std::distance(id.begin(), it)) {
// if at position 3 or 5, output a dash
case 3:
case 5:
out << '-';
// output the number (no break, so regardless of position)
default:
out << *it;
}
}
// return the string
return out.str();
};
// print out as normal, until line 53
<< setw(17) << printDashes(List[i].Id) << setw(16) << calcAverage(List[i])
// etc.
}
This may be slightly complicated, and there is probably a better way of doing it, this is just how I thought of doing it off the top of my head. Also, this assumes that "ID" is being stored as a std::string and that you have got #include <sstream> at the top of your code.