Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "std_lib_cmpt125.h"
- //////////////////////////////////////////////
- //
- // Global Variables
- //
- //////////////////////////////////////////////
- vector<double> numbers;
- double sum = 0;
- double n1;
- double smallest;
- double largest;
- double x;
- const string prompt = "Enter one number: ";
- string s1;
- /////////////////////////////////////////////
- //
- // Helper Functions
- //
- /////////////////////////////////////////////
- double find() {
- if((s1[s1.size()-1] == 'm' && s1[s1.size()-2] != 'c') ||
- (s1[s1.size()-2] == 'm' && s1[s1.size()-3] != 'c')) {
- istringstream iss(s1);
- iss >> x;
- n1 = x;
- return n1;
- } else if(s1[s1.size()-2] == 'c' || s1[s1.size()-3] == 'c') {
- istringstream iss(s1);
- iss >> x;
- n1 = x;
- n1 = (n1/100);
- return n1;
- } else if(s1[s1.size()-1] == 't' || s1[s1.size()-2] == 't') {
- istringstream iss(s1);
- iss >> x;
- n1 = x;
- n1 = (((n1*12)*2.54)/100);
- return n1;
- } else if(s1[s1.size()-1] == 'n' || s1[s1.size()-2] == 'n') {
- istringstream iss(s1);
- iss >> x;
- n1 = x;
- n1 = ((n1*2.54)/100);
- return n1;
- } else{
- error("That unit is not accepted.");
- return 0;
- }
- }
- double find_sum() {
- if(numbers.size() != 0) {
- for(unsigned int i = 0; i < numbers.size(); ++i) {
- sum = sum + numbers[i];
- return sum;
- }
- } else{
- error("You haven't entered any numbers.");
- return 0;
- }
- }
- //////////////////////////////////////////////
- //
- // Main Function
- //
- //////////////////////////////////////////////
- int main() {
- cout << prompt;
- while(cin >> s1) {
- try{
- if(s1 == "|") {
- cout << "The smallest value is: " << smallest << endl;
- cout << "The largest value is: " << largest << endl;
- cout << "The number of values is: " << numbers.size() << endl;
- cout << "The sum of the values is: " << find_sum() << endl;
- return 0;
- } else{
- find();
- numbers.push_back(n1);
- sort(numbers.begin(), numbers.end());
- smallest = numbers[0];
- largest = numbers[numbers.size()-1];
- if(n1 == smallest) {
- cout << n1 << " the smallest so far. \n";
- } else if(n1 == largest){
- cout << n1 << " the largest so far. \n";
- } else{
- cout << n1 << endl;
- }
- cout << prompt;
- } //else
- } catch(runtime_error e) {
- cout << e.what() << endl;
- cout << prompt;
- } //while
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment