1
0

scale implement

This commit is contained in:
Captain ALM 2022-10-28 10:20:04 +01:00
parent 77fdbf36dc
commit f67603bc36
3 changed files with 12 additions and 6 deletions

View File

@ -20,20 +20,22 @@ int prompti(string,bool*);
double promptd(string,bool*); double promptd(string,bool*);
double avgitr(std::list<double>*); double avgitr(std::list<double>*);
double avgfor(std::list<double>*); double avgfor(std::list<double>*);
void scale(std::list<double>&,double);
int main() { int main() {
printlm("Average of:"); printlm("Scale:");
bool s {}; bool s {};
std::list<double> lst {}; std::list<double> lst {};
do { do {
auto v = promptd("Enter a double value: ", &s); auto v = promptd("Enter a double value: ", &s);
if (s) lst.push_back(v); if (s) lst.push_back(v);
} while (s); } while (s);
printm("avgitr: "); auto scalef = promptd("Enter double scalar: ", &s);
printlm(avgitr(&lst)); if (!s) return -1;
printm("avgfor: "); printlm("Scaled:");
printlm(avgfor(&lst)); scale(lst, scalef);
for (const auto c : lst) printlm(c);
return 0; return 0;
} }
@ -71,6 +73,10 @@ double avgitr(std::list<double> *values) {
double avgfor(std::list<double> *values) { double avgfor(std::list<double> *values) {
double sum {}; double sum {};
for (auto c : *values) sum += c; for (const auto c : *values) sum += c;
return sum / values->size(); return sum / values->size();
} }
void scale(std::list<double> &values, double sf) {
for (auto &c : values) c *= sf;
}

BIN
main.o

Binary file not shown.

BIN
t

Binary file not shown.