Advertisement
Lukasz_Miskiewicz

operacje na plikach zad 8

May 24th, 2020
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.87 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <ctime>
  4. #include <fstream>
  5. #include <sstream>
  6. using namespace std;
  7. int a,b,c;
  8.  
  9. int main()
  10. {
  11.     cout<<"podaj 6 liczb z zakresu 1 do 49"<<endl;
  12.     ofstream plik("liczby.txt");
  13.  
  14.     for(int i=0; i<6; i++)
  15.     {
  16.         cin>>a;
  17.         while(a<1 || a>49)
  18.         {
  19.             cout << "zla wartosc";
  20.             cin>>a;
  21.         }
  22.         plik<<a<<endl;
  23.     }
  24.     int tab[6];
  25.     for(int i=0; i<6; i++)
  26.     {
  27.         tab[i]=1+rand()%(49);
  28.         cout<<tab[i] << " ";
  29.     }
  30.  
  31.     c=0;
  32.     ifstream odczyt_pliku("liczby.txt");
  33.     string odczyt;
  34.     for(int i=0; i<6; i++)
  35.     {
  36.         getline(odczyt_pliku,odczyt);
  37.         stringstream zamiana(odczyt);
  38.         int x=0;
  39.         zamiana>>x;
  40.  
  41.         if(x==tab[i])
  42.         {
  43.             c++;
  44.         }}
  45.  
  46.     cout<<endl<<"wynik: "<<c;
  47.     return 0;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement