Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <string>
- #include <vector>
- #include <iostream>
- #include <algorithm>
- using namespace std;
- double smaller(double a, double b)
- {
- if (a < b) return a;
- return b;
- }
- double larger(double a, double b)
- {
- if (a > b) return a;
- return b;
- }
- double to_meters(double v, string unit)
- {
- double sum = 0;
- if (unit == "m") {
- sum += v;
- } else if (unit == "cm") {
- sum = sum + (v/100);
- } else if (unit == "in") {
- sum = sum + ((v * 2.54)/100);
- } else if (unit == "ft") {
- sum = sum + ((v * 12 * 2.54)/100);
- }
- return sum;
- }
- int main()
- {
- double last_smallest = -1, last_largest = -1;
- double amount = 0, cm, in, ft, m, total = 0;//, y;
- vector<string> smallest;
- vector<string> largest;
- vector<string> all;
- vector<double> all_in_meters;
- string unit, smallest_s, largest_s;
- cout << "Enter a scale amount and the scales respective unit: " << "\n";
- while (cin >> amount >> unit) {
- amount = amount;
- unit = unit;
- if (last_smallest == -1 and last_largest == -1) {
- last_smallest, last_largest = amount;
- smallest.push_back( to_string(amount) + unit );
- largest.push_back( to_string(amount) + unit );
- } else {
- if (smaller(last_smallest, amount) < last_smallest) {
- last_smallest = amount;
- smallest_s = (to_string(amount) + unit);
- smallest.push_back( smallest_s );
- } else if (larger(last_largest, amount) > last_largest) {
- last_largest = amount;
- largest_s = (to_string(amount) + unit);
- largest.push_back( largest_s );
- }
- }
- if (unit == "cm") {
- cm = amount;
- total += to_meters(amount, unit);
- cout << "There are " << cm << "cm in " << amount << "cm\n";
- } else if (unit == "in") {
- in = amount * 2.54;
- total += to_meters(amount, unit);
- cout << "There are " << in << "cm in " << amount << "in\n";
- } else if (unit == "ft") {
- ft = amount * 12;
- total += to_meters(amount, unit);
- cout << "There are " << ft << "in in " << amount << "ft\n";
- } else if (unit == "m") {
- total += to_meters(amount, unit);
- cm = amount * 100;
- cout << "There are " << cm << "cm in " << amount << "m\n";
- } else {
- cout << "Did not recognize that unit, your request is rejected. Sorry bro...\n";
- }
- all.push_back( to_string(amount) + unit );
- all_in_meters.push_back( to_meters(amount, unit) );
- }
- cout << "Your total inputs turned out to be: " << total << " meters.\n";
- if (largest.size() > 0)
- cout << "The largest input value so far: " << largest[largest.size() - 1] << "\n";
- if (smallest.size() > 0)
- cout << "The smallest input value so far: " << smallest[smallest.size() - 1] << "\n";
- if (all.size() > 0)
- cout << "All inputs in original order: \n";
- for (int i=0; i < all.size(); ++i)
- cout << "Input " << i << "\t" << all[i] << "\n";
- if (all_in_meters.size() > 0)
- cout << "All inputs (converted to meters) in sorted order: \n";
- sort( all_in_meters.begin(), all_in_meters.end() );
- for (int i=0; i < all_in_meters.size(); ++i)
- cout << "Input " << i << "\t" << all_in_meters[i] << "\n";
- // while (cin >> x) {
- // }
- // cout << "Enter two integers in sequence: " << "\n";
- // while (cin >> x >> y) {
- // // cout << "Integers: " << x << " " << y << "\n";
- // if (x == y) {
- // cout << "The two numbers entered are equal" << "\n";
- // } else {
- // if (larger(x,y) - smaller(x, y) <= 1.0/100) {
- // cout << "The numbers entered are almost equal" << "\n";
- // } else {
- // cout << "The smaller value is: " << smaller(x,y) << "\n";
- // cout << "The larger value is: " << larger(x,y) << "\n";
- // }
- // }
- // }
- // for (int a, b; cin>>a>>b;) {
- // cout << a << " " << b << "\n";
- // }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement