#include #include #include #include using string = std::string; //Placw in header! template void printm(T m){ std::cout << m; } template void printlm(T m){ printm(m); printm("\n"); } typedef std::vector::size_type vtype; double promptd(string,bool*); int main() { std::setprecision(3); printlm("Calculate median and average from sequence:"); std::vector v{}; bool s {}; do { auto d = promptd("Enter a number (Enter non-number to complete entry) : ",&s); if (s) v.push_back(d); } while(s); sort(v.begin(), v.end()); printm("The count is: "); printlm(static_cast(v.size())); printm("The median is: "); int halfway {static_cast(v.size()) / 2}; if (static_cast(v.size())%2 == 1) printlm(v.at(static_cast(halfway))); else printlm((v.at(static_cast(halfway - 1)) + v.at(static_cast(halfway))) / 2.0); double avg {}; for (vtype i = 0; i < v.size(); ++i) avg += v.at(i); avg /= static_cast(v.size()); printm("The average is: "); printlm(avg); return 0; } double promptd(string message, bool *status) { double tr {}; *status = false; std::cout << message; if (!(std::cin >> tr)){ std::cin.clear(); std::cin.ignore(); return 0; } *status = true; return tr; }