Mar 28, 2009 at 7:40am UTC
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!!!!!
Mar 28, 2009 at 3:18pm UTC
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
Mar 28, 2009 at 3:58pm UTC
There are fewer than 6*5*4 = 120 such combinations given the example input above.
Mar 30, 2009 at 11:13am UTC
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 Apr 4, 2009 at 3:13am UTC
Apr 4, 2009 at 1:57pm UTC
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?