diff options
author | zedarider <ymherklotz@gmail.com> | 2016-02-18 11:37:45 +0000 |
---|---|---|
committer | zedarider <ymherklotz@gmail.com> | 2016-02-18 11:37:45 +0000 |
commit | af98ee7ff28cff97f5f29a5d9e65f9153531b0ee (patch) | |
tree | 86bfc53a0bc04512ac2936ee067a2b43e901e688 /MinMax.cpp | |
download | imperial_2015-af98ee7ff28cff97f5f29a5d9e65f9153531b0ee.tar.gz imperial_2015-af98ee7ff28cff97f5f29a5d9e65f9153531b0ee.zip |
Imperial C++ Directory
These are all the projects I’ve been working on at university.
Diffstat (limited to 'MinMax.cpp')
-rw-r--r-- | MinMax.cpp | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/MinMax.cpp b/MinMax.cpp new file mode 100644 index 0000000..070c33f --- /dev/null +++ b/MinMax.cpp @@ -0,0 +1,42 @@ +#include <iostream> +#include <vector> +#include <string> +#include <sstream> + +using namespace std; + +int main() { + double input, maxtmp, maxloc, mintmp, minloc, + addtmp, average; + vector<double> vin; + + cout << "Enter Number <q to exit>: "; + cin >> input; + + do { + cout << "Enter Number <q to exit>: "; + vin.push_back(input); + } while(cin >> input); + + mintmp = vin[0]; + maxtmp = vin[0]; + addtmp = 0; + + // cout << "values: " << mintmp << ", " << maxtmp << endl; + + for(int i = 0; i < vin.size(); i++) { + if(maxtmp <= vin[i]) { + maxtmp = vin[i]; + maxloc = i; + } else if (mintmp >= vin[i]) { + mintmp = vin[i]; + minloc = i; + } + addtmp += vin[i]; + } + average = addtmp / vin.size(); + cout << "\nmin: " << mintmp << " at pos: " << minloc << "\nmax: " + << maxtmp << " at pos: " << maxloc << "\naverage: " << + average << endl; + return 0; +} |