Zitat [...]Da ich weder so ein Programm noch einen W 20 besitze, bleibe ich wohl doch bei meiner alten Methode ... Code: #include <iostream> #include <cstdlib> #include <conio.h> using namespace std; int main() { int numbers[20]; int puffer; bool schonda; cout << "Program zur Ausgabe von 20 Nummern\n"; cout << "Druecken sie eine Taste\n"; while(! kbhit()) rand(); cout << "\n\n"; for(int k=0; k<20; ) { schonda =false; puffer = rand() % 20; for(int i = 0; i<20;i++) if(puffer==numbers[i]) schonda = true; // ob die Nummer schon vergeben wurde if (schonda == false){ numbers[k]=puffer; k++; } } for(int i =0; i<20;i++) cout << "Nummer " << i+1 << " = " << numbers[i]+1 << endl; system("pause"); return 0; } Das noch kompilieren und das Problem dürfte erledigt sein Wobei das Programm 0 - 19, ausgibt, Ne, jetzt passt das auch.
#include <iostream> #include <cstdlib> #include <conio.h> using namespace std; int main() { int numbers[20]; int puffer; bool schonda; cout << "Program zur Ausgabe von 20 Nummern\n"; cout << "Druecken sie eine Taste\n"; while(! kbhit()) rand(); cout << "\n\n"; for(int k=0; k<20; ) { schonda =false; puffer = rand() % 20; for(int i = 0; i<20;i++) if(puffer==numbers[i]) schonda = true; // ob die Nummer schon vergeben wurde if (schonda == false){ numbers[k]=puffer; k++; } } for(int i =0; i<20;i++) cout << "Nummer " << i+1 << " = " << numbers[i]+1 << endl; system("pause"); return 0; }
Geändert von Mivey (08.02.2010 um 16:39 Uhr)
Stichwortwolke anzeigen
Foren-Regeln