diff --git "a/S\303\251rie 13/stdin_read.cc" "b/S\303\251rie 13/stdin_read.cc" new file mode 100644 index 0000000..0880c8c --- /dev/null +++ "b/S\303\251rie 13/stdin_read.cc" @@ -0,0 +1,43 @@ +// stdin_read.cc +// Auteur : Quentin Berling +// Version : 1.0 +#include +#include +using namespace std; + +bool is_number(const string &s); + +int main() { + int i(0), a(0); + string cstring; + + while(cin) { + cin >> cstring; + if (is_number(cstring) == true) { + a+=stoi(cstring); + cstring.clear(); + ++i; + } + } + + if (i > 0) { + cout << "La moyenne des entiers entrés est " << 1.0*a/i << "." << endl; + } + + return 0; +} + +bool is_number(const string &s) { + std::string::const_iterator it = s.begin(); + while (it != s.end() && (std::isdigit(*it) || (*it == '-'))) + ++it; + return !s.empty() && it == s.end(); +// size_t nb(0); +// if (s.size() != 0) { +// long x=stol(s, &nb); +// } else { +// return 0; +// } +// +// return (nb == s.size()); +}