grodek118

Zgadywanie liczby losowej

Aug 10th, 2020
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <ctime>
  4.  
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9. srand( time(NULL));
  10. int losowana_liczba = (rand() % 1000) + 1;
  11. int liczba;
  12. int ilosc;
  13. while(true){
  14.  
  15. cout << "Podaj liczbe z zakresu od 1 do 1000" << endl;
  16. cin >> liczba;
  17. ilosc++;
  18.  
  19. if(liczba < 1 || liczba > 1000)
  20. {
  21. cout << "Podales liczbe poza zakresem!" << endl;
  22. }
  23. else
  24. {
  25. if(liczba > losowana_liczba)
  26. {
  27. cout << "Liczba za duza" << endl;
  28. }
  29. else if(liczba < losowana_liczba)
  30. {
  31. cout << "Liczba za mala" << endl;
  32. }
  33. else
  34. {
  35. cout << "Prawidlowa odpowiedz!" << endl;
  36. break;
  37. }
  38. }
  39. }
  40. cout << "Liczba prob: " << ilosc << endl;
  41. return 0;
  42. }
  43.  
Advertisement
Add Comment
Please, Sign In to add comment