wiedermal lotto...
-
hallo zusammen
/*#include <stdio.h> #include <stdlib.h>*/ #include <iostream> #include <iomanip> #include <ctime> #include <string> using namespace std; int main() { int zufallszahl, i; int array[] = {0,0,0,0,0,0}; char n; do { cout << "wollen Sie Lotto spielen dann druecken Sie die j fuer ja"<<endl; cout << "wollen Sie aufhoeren druecken Sie eine eine beliebige Taste ausser j"<<endl; cin >> n ; if (n == 'j') { srand( time(0) ); for (i=0;i<6;i++) { zufallszahl = rand() % 50 + 1; if (zufallszahl == array[0] || zufallszahl == array[1] || zufallszahl == array[2] || zufallszahl == array[3] || zufallszahl == array[4] || zufallszahl == array[5]) i--; else cout << zufallszahl << endl; array[i]=zufallszahl; //cout << "array" << array[i] << endl; } } else; } while (n =='j'); return 0; }trotz meiner if bediengung, wo die zufallszahl mit den arraywerten verglichen wird, bekomm ich ab und zu gleiche zahlen raus.
hab ich was übersehn?
-
Vielleicht solltest du die beiden Anweisungen hinter dem else zu einer Compound-Anweisung klammern - so wie das Programm jetzt dasteht, wird nur die Ausgabe von dem if-else erfasst und nicht das Eintragen in dein Array.
-
danke fürn tipp, jetzt funzt alles!