Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "std_lib_facilities.h"
- int main() // C++-Programme beginnen mit der Ausführung von main
- {
- double val1 =0.0;
- double l_sum =0.0; // Summe aller Werte in Meter
- vector<double> inputs; // Vektor für die ersten Eingaben
- vector<double> meter_inputs; // Vektor für die Meter Werte
- string unit; // Variable für die Einheit
- const double f_cm_m =0.01; // Umrechnungsfaktor von, nach Meter
- const double f_in_m =0.0254;
- const double f_ft_m =0.0348;
- while (cin >> val1 >> unit)
- {
- if (unit != "cm" && unit != "m" && unit != "in" && unit != "ft") // Prüfen auf gültige Eingabe
- cout << "Falsche Einheit!\n";
- else
- {
- inputs.push_back(val1); // schreibe normale Eingabe in Vektor
- if (unit == "cm")
- {
- l_sum = l_sum + (val1*f_cm_m); // 1cm=0,01 Meter
- meter_inputs.push_back(val1*f_cm_m); // schreibe Meter Wert in Vektor
- }
- if (unit == "in")
- {
- l_sum = l_sum + (val1*f_in_m); // in*2.54cm/100cm=Meter
- meter_inputs.push_back(val1*f_in_m);
- }
- if (unit == "ft")
- {
- l_sum = l_sum + (val1*f_ft_m); // ft*12in*2.54cm/100cm=Meter
- meter_inputs.push_back(val1*f_ft_m);
- }
- if (unit == "m")
- {
- l_sum = l_sum + val1;
- meter_inputs.push_back(val1);
- }
- }
- }
- // Nach eingabe STRG+D
- sort(inputs.begin(),inputs.end()); // sortiere normale Eingaben
- sort(meter_inputs.begin(),meter_inputs.end()); // sortiere Meter Eingaben
- cout << "BERECHNET:-------\n";
- cout << "größter Wert: " << inputs[inputs.size()-1] << endl;
- cout << "kleinster Wert: " << inputs[0] << endl;
- cout << "Summe: " << l_sum << " Meter" << endl;
- cout << "Anzahl: " << inputs.size() << " Eingaben" << endl;
- for (int i =0;i<meter_inputs.size();++i)
- cout << meter_inputs[i] << "m" << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement