Advertisement
Michal_Pilarski

zad8 operacje na plikach

May 20th, 2020
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.96 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <cstdlib>
  4. #include <ctime>
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9.     int tab[6], tab2[6], trafione=0;
  10.     srand(time(NULL));
  11.  
  12.     ofstream zapis_do_pliku ("liczby.txt");
  13.     if (!zapis_do_pliku.is_open())
  14.     {
  15.         cout<<"Brak dostepu do pliku" ;
  16.     }
  17.     cout << "Lotto podaj liczby" << endl;
  18.     for(int i=1; i<=6; i++)
  19.     {
  20.         cout<<"Podaj "<<i<<" liczbe: ";
  21.         cin>>tab[i];
  22.         if(tab[i]<1 || tab[i]>49)
  23.         {
  24.             cout<<"Podawaj liczby z zakresu 1-49 ok? :)";
  25.             return 0;
  26.         }
  27.         zapis_do_pliku<<tab[i]<<endl;
  28.     }
  29.  
  30.     for(int i=1; i<=6; i++)
  31.     {
  32.        tab2[i] = rand()%48+1;
  33.     }
  34.     for(int i=1; i<=6; i++)
  35.     {
  36.        for(int j=1; j<=6; j++)
  37.         {
  38.             if(tab[i]==tab2[j])
  39.             {
  40.                 trafione++;
  41.             }
  42.         }
  43.     }
  44.     cout<<"Trafiles "<<trafione<<" liczb"<<endl;
  45.  
  46.     return 0;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement