Hey guys,
actually i got a little problem with my code.
In fact it should be easy, but the output of the program is not like it should be.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
|
#include "myError.h"
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using std::cin;
using std::cout;
int main() try {
int ix{};
int iy{};
int iz{};
std::vector<int> iOrdnen{};
iOrdnen.push_back(ix);
iOrdnen.push_back(iy);
iOrdnen.push_back(iz);
cout << "Bitte geben Sie drei Werte (ix, iy und iz) an: ";
cin >> ix >> iy >> iz;
std::sort(iOrdnen.begin(), iOrdnen.end());
for (unsigned int i{0U}; i < iOrdnen.size(); ++i) {
cout << iOrdnen.at(i) << "\n";
cout << "\n\t" << "Ihre eingebenen Zahlen lauten: " << ix << "," << iy << "," << iz;
}
if (ix < 999 && iy < 999 && iz < 999) {
if (ix > 0 && iy > 0 && iz > 0) {
int isumme = ix + iy + iz;
cout << "\n\t" << "Die Summe aller Zahlen betraegt: " << isumme;
int iprodukt = ix * iy * iz;
cout << "\n\t" << "das Produkt aller Zahlen betraegt: " << iprodukt;
cout << "\n\t";
int idifferenz1 = ix - iy;
int idifferenz2 = iy - iz;
cout << "\n\t" << "Die Differenz aus ix und iy betraegt: " << idifferenz1;
cout << "\n\t" << "Die Differenz aus iy und iz betraegt: " << idifferenz2;
cout << "\n\t";
double iquotient1 = ix / (iy * 1.0);
double iquotient2 = iy / (iz * 1.0);
cout << "\n\t" << "Der Quotient aus ix und iy betraegt: " << iquotient1;
cout << "\n\t" << "Der Quotient aus iy und iz betraegt: " << iquotient2;
cout << "\n\t";
} else
error("Negative Zahlen sind nicht erlaubt!");
cout << "\n\t";
return main();
} else
cout << "Deine eingebenen Zahlen sind ungueltig." << "\n\t";
cout << "\n\t";
return main();
} catch (std::exception &e) {
std::cerr << e.what();
return -2;
} catch (...) {
std::cerr << "Ein Fehler";
return -1;
}
|
At the beginning of main() there is the method for sorting.
In my case the user have to put three values, each for x,y and z, but they don't get sorted afterwards.
If i change "iOrdnen.at(i)" to "iOrdnen.at(1)" the program adds the value of x to the last digit.
For example: The user sets for x = '2' , for y= 12 and for z = 4
The output will be like: 2,12,4'2'
And that problem affects the calculation.
What did i wrong?