diff --git a/main.cpp b/main.cpp index dc71104..115ab18 100644 --- a/main.cpp +++ b/main.cpp @@ -20,20 +20,22 @@ int prompti(string,bool*); double promptd(string,bool*); double avgitr(std::list*); double avgfor(std::list*); +void scale(std::list&,double); int main() { - printlm("Average of:"); + printlm("Scale:"); bool s {}; std::list lst {}; do { auto v = promptd("Enter a double value: ", &s); if (s) lst.push_back(v); } while (s); - printm("avgitr: "); - printlm(avgitr(&lst)); - printm("avgfor: "); - printlm(avgfor(&lst)); + auto scalef = promptd("Enter double scalar: ", &s); + if (!s) return -1; + printlm("Scaled:"); + scale(lst, scalef); + for (const auto c : lst) printlm(c); return 0; } @@ -71,6 +73,10 @@ double avgitr(std::list *values) { double avgfor(std::list *values) { double sum {}; - for (auto c : *values) sum += c; + for (const auto c : *values) sum += c; return sum / values->size(); } + +void scale(std::list &values, double sf) { + for (auto &c : values) c *= sf; +} diff --git a/main.o b/main.o index 647db1a..e6909c2 100644 Binary files a/main.o and b/main.o differ diff --git a/t b/t index c16de3c..5fec8c9 100755 Binary files a/t and b/t differ