#include using namespace std; int *alloue_tableau(int taille) { return new int[taille]; } int *lire_numeros(void) { int *numeros = alloue_tableau(6); for (int i=0; i<6; i++) { cout << "Numero " << i+1 << ": "; do cin >> numeros[i]; while (numeros[i] < 1 || numeros[i] > 45); } return numeros; } int compte_numeros_corrects(int *t1, int *t2) { int matches = 0; for (int i=0; i<6; i++) for (int j=0; j<6; j++) if (t1[i] == t2[j]) matches++; return matches; } void stocke_numeros_corrects(int *t1, int *t2, int *c) { int index = 0; for (int i=0; i<6; i++) for (int j=0; j<6; j++) if (t1[i] == t2[j]) { c[index] = t1[i]; index++; } } void affiche_numeros(int *t, int taille) { for (int i=0; i<taille; i++) cout << t[i] << " "; cout << endl; } int main(int argc, char **argv) { cout << "Veuillez entrer le resultat du tirage:" << endl; int *tirage = lire_numeros(); cout << endl << "Veuillez entrer vos numeros:" << endl; int *numeros_perso = lire_numeros(); int nombre_corrects = compte_numeros_corrects(tirage, numeros_perso); int *corrects = alloue_tableau(nombre_corrects); stocke_numeros_corrects(tirage, numeros_perso, corrects); cout << "Vous avez joue " << nombre_corrects << " numero(s) correct(s)." << endl; cout << "Numeros du tirage:" <<endl; affiche_numeros(tirage, 6); cout << endl << "Vos numeros corrects:" << endl; affiche_numeros(corrects, nombre_corrects); delete [] corrects; delete [] numeros_perso; delete [] tirage; return 0; }
Pages: 1 2