Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdlib>
- #include <ctime>
- #include <fstream>
- #include <sstream>
- using namespace std;
- int a,b,c;
- int main()
- {
- cout<<"podaj 6 liczb z zakresu 1 do 49"<<endl;
- ofstream plik("liczby.txt");
- for(int i=0; i<6; i++)
- {
- cin>>a;
- while(a<1 || a>49)
- {
- cout << "zla wartosc";
- cin>>a;
- }
- plik<<a<<endl;
- }
- int tab[6];
- for(int i=0; i<6; i++)
- {
- tab[i]=1+rand()%(49);
- cout<<tab[i] << " ";
- }
- c=0;
- ifstream odczyt_pliku("liczby.txt");
- string odczyt;
- for(int i=0; i<6; i++)
- {
- getline(odczyt_pliku,odczyt);
- stringstream zamiana(odczyt);
- int x=0;
- zamiana>>x;
- if(x==tab[i])
- {
- c++;
- }}
- cout<<endl<<"wynik: "<<c;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement