Advertisement
Narzew

Lotto

Oct 19th, 2013
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.00 KB | None | 0 0
  1. #include <cstdlib>
  2. #include <iostream>
  3.  
  4. using namespace std;
  5.  
  6. int randomize(int min, int max){
  7.     return (rand()%(max-(min-1))+min);
  8. }
  9.  
  10. bool wylosowano(int x, int *wylosowane){
  11.     for(int i=0;sizeof(wylosowane);i++){
  12.         if (wylosowane[i] == x){
  13.             return true;
  14.         }
  15.     }
  16.     return false;
  17. }
  18.  
  19. void wypisz(int *wylosowane){
  20.     cout << "Twoje numery to: ";
  21.     for(int i=0;i<6;i++){
  22.         if (i==5){
  23.             cout << wylosowane[i]<<"\n";
  24.         } else {
  25.             cout << wylosowane[i]<<", ";
  26.         }
  27.     }
  28. }
  29.  
  30. void wylosuj(){
  31.     int liczby[49] = {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};
  32.     int wylosowane[6],wylosowana,wylosowanych;
  33.     for(;sizeof(wylosowane)<6;){
  34.         wylosowana=liczby[randomize(1,49)-1]; // Wylosowana liczba 
  35.         if (wylosowano(wylosowana,wylosowane)){
  36.         } else {
  37.             wylosowane[wylosowanych] = wylosowana;
  38.             wylosowanych++;
  39.         }
  40.     }
  41.     wypisz(wylosowane);
  42. }
  43.  
  44.  
  45. int main(){
  46.     srand(time(NULL));
  47.     wylosuj();
  48.     return 0;
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement