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 avgitr(std::list<double>*);
double avgfor(std::list<double>*);
void scale(std::list<double>&,double);
int main() {
printlm("Average of:");
printlm("Scale:");
bool s {};
std::list<double> 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<double> *values) {
double avgfor(std::list<double> *values) {
double sum {};
for (auto c : *values) sum += c;
for (const auto c : *values) sum += c;
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.