help on writing a simple numbers combinations program

hi , i'm new to this forum , may i say this is a great site , now i want some pointer pls on writing this program in c++ ,
i am trying to write a program where the user input 10 numbers and from the the program will generates let's say 20 best combinations set of 3 possibles
what i mean is this let say the user input 0 3 4 6 7 8 9 1
and it will generate a couple set of 3 for example : 046 037 etc

or A B C D E F G H I J = ABF ABG ABH ABI ABJ OR FGH FGI FGJ OR GHI GHJ

i will really appreciate if you or anyone can help me on that thx for everything.

I would probably start by putting each character the user inputs into an array and then randomly combine three elements in the array. I hope that this is some help to you.
I hope this code helps you

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
#include <iostream.h>
#include <conio.h>


#define  INPUT_LENGTH        10
#define  OUPUT_SEQUENCE_LEN   3
#define  N_OF_COMBINATIONS   20


long min(long a, long b) {
	return (a < b) ? a : b;
}


void main() {
	char input[INPUT_LENGTH + 1];
	char output[N_OF_COMBINATIONS][OUPUT_SEQUENCE_LEN + 1];

	cout << "write a sequance of letter or number ending with the '.' character" << endl;
	cout << ">";
	cin.getline(input, INPUT_LENGTH, '.');
	cout << endl;

	for(int i = 0; i < N_OF_COMBINATIONS; i++) {
		for(int j = 0; j < OUPUT_SEQUENCE_LEN; j++) {
			output[i][j] = input[rand() % min(INPUT_LENGTH, strlen(input))];
		}
		output[i][OUPUT_SEQUENCE_LEN] = '\0';
	}

	for(int i = 0; i < N_OF_COMBINATIONS; i++) {
		cout << i << ") " << output[i] << endl;
	}

	getch();
}

Last edited on
Topic archived. No new replies allowed.