I think that this post should have been on a separate thread, to leave
this one for a more complex project. Just an ideea.
Regarding that problem I do not find it on my archive of code written
by me.
But I will try to solve it now. Any way that style of solvong a
problem is something like very very very brute force :)
But is OK for now.
The ideea in programming as I found out after comparing my early
solutions to those of experienced programmers, seemed like comparing a
cottage with a modern car.
The ideea for this problem is to make an algorithm that will solve the
problem also for 4, 5 or 6, or more variables.
I think that you have solved all the combinations of those 3
variables, but what you will do if you have 26 variables ?
Or 2317659 variables ? Your algorithm will not work ...
Something that will work with any number of variables, and you will
learn in the future chapter (how to use vector) is like this :
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
vector<int> v;
int value;
while (cin >> value)
v.push_back(value);
sort (v.begin(),v.end());
for (int i=0; i<v.size(); ++i)
cout << v[i] << " , ";
}
Or if you whant to make your self a sorting algorithm and not use that
of the standard library, here is another sample of code :
#include <iostream>
#include <vector>
using namespace std;
int main()
{
vector<int> v;
int value;
while (cin >> value)
v.push_back(value);
// sorting algorithm for any number of integers
for (int i=0; i<v.size(); ++i)
for (int j=i+1; j<v.size(); ++j)
// if I found that a number is smaller then then a previous one I
switch them
if (v[j] < v[i]) {
int temp = v[i];
v[i] = v[j];
v[j] = temp;
}
// printing the integers sorted in ascending order
for (int i=0; i<v.size(); ++i) {
//if I am at the last integer, do not output any more commas, just a
newline
if (i == v.size()-1) {
cout << v[i] << endl;
break;
}
// otherwise output the integers folowed by commas
cout << v[i] << " , ";