Number Generator

Hi everyone!!!! Im a beginner in c++!!! I want to make a program that displays a 3 number combinations from the inputted numbers....

Example: 3 4 5 3 4 1
displays

345
334
445
354
453
133
144......anything that make 3 number comb.


I need your tips in programing..... I want to learn this course.... Thank you in advance!!!!!
You can store your numbers in an array or container, use permutation algorithms ( http://www.cplusplus.com/reference/algorithm/next_permutation.html ) and display the first three elements of the permutated array
I wreckon store the inputed numbers in an array and then cycle through using for loops. Its going to take quite a lot to get very possible combination though. I would recommend maybe having a smaller amount of numbers to get how your program is going ot work first
There are fewer than 6*5*4 = 120 such combinations given the example input above.
ok i got it
ty Bazzy
but my program repeats a number
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
73
74
75
#include<iostream>
#include<fstream>
#include<algorithm>
using namespace std;

int NumGen()
{
system("cls");
int array[0], n=-1, num; 

ofstream myfile;
myfile.open("NumGen.doc");

cout<<"Enter number combination: ";

do{	cin>>num;
    myfile<<num<<"\t";
    n=n+1;
    array[n]=num;}while(num!=100);

for(int x=0; x+2!=n; x=x+1){
        for(int y=x+1; y+1!=n; y=y+1)
                for(int z=y+1; z!=n; z=z+1){
                        cout<<array[x]<<array[y]<<array[z]<<"\t";
                        myfile<<"\n"<<array[x]<<array[y]<<array[z];}}
myfile.close();
}

int ShowAll()
{   system("cls");
int array[0], n=-1, num; 

ofstream myfile;
myfile.open("NumGen.doc");

cout<<"Enter number combination: ";

do{	cin>>num;
    myfile<<num<<"\t";
    n=n+1;
    array[n]=num;}while(num!=100);
    
    sort (array,array+n);

  do {
    cout  << array[0] << array[1] <<  array[2]<< "\t";
    myfile  << endl<< array[0] << array[1] <<  array[2];
  } while ( next_permutation (array,array+n) );
}

int menu()
{int opt;

cout<<"\t\t\t\t\tMENU\n********************************************************************************"
    <<"1. Generate Number\n2. Show All Combination\n3. Show Unrepeated Combination\nEnter option: ";
cin>>opt;
    
    switch (opt)
           {case 1:
                 NumGen();break;
           case 2:
                ShowAll();break;
           default: 
           return 0;}}



int main()
{
menu();

system("PAUSE");
return 0;
}


i want to include in the 3rd option to show the unrepeated combination....

example:
123
132
213
231
312
321

i want to show only 1 combination in that numbers(ex. 123) because it has 3 identical number the 1, 2 and 3......

how i can do that???????
Last edited on
any reply????
Do you or do you not want to show duplicates?

If the array is 1, 2, 2, 3 do you want to show 1 2 3 only once or multiple times?
Topic archived. No new replies allowed.