// program to give user option of displaying arithmetic mean, harmonic mean or root mean square of a set of values #include #include #include int main() { try { std::cout << "This program will allow you to view either the arithmetic mean, harmonic mean or root mean square of a set of values." << '\n'; std::cout << "How many values do you wish to enter? " << '\n'; int count(0); std::cin >> count; if (not std::cin) throw std::exception(); int numcount(0); double value(0.0); double meantotal(0.0); double harmtotal(0.0); double harmresult(0.0); double rsm_total(0.0); double arith_mean(0.0); do { std::cout << "Please Type a number :"; std::cin >> value; if (not std::cin) throw std::exception(); ++numcount; meantotal += value; harmresult = (1/value); harmtotal += harmresult; rsm_total += value * value; arith_mean = rsm_total/count; } while (numcount < count); double average = meantotal/count; double harmonicmean = count/harmtotal; double rsm = std::sqrt(arith_mean); do { std::cout << "Thank You for entering these values. Please indicate which calculation you want to see." << '\n'; std::cout << "Press '1' to see the Mean\n"; std::cout << "Press '2' to see the Harmonic Mean\n"; std::cout << "Press '3' to see the Root Square Mean\n"; std::cout << "Enter '999' to end the program\n"; std::cout << "VIEW :"; int view(0); std::cin >> view; if (not std::cin) throw std::exception(); if (view == 999) break; if (view == 1) { std::cout << "The Arithmetic Mean of these values is " << average << '\n'; } if (view == 2) { std::cout << "The Harmonic Mean of these values is " << harmonicmean << '\n'; } if (view == 3) { std::cout << "The Root Square Mean of these values is " << rsm << '\n'; } } while (true); } catch (...) { std::cerr << "***An exception was thrown.***\n"; } }