fork download
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. int main() {
  7. string haslo = "komputer";
  8. string odgadniete = "________";
  9.  
  10. int max_proby = 10;
  11. int licznik = 0;
  12. int wygrana = 0;
  13.  
  14. cout << "Liczba liter: " << haslo.length() << endl;
  15.  
  16. while (licznik < max_proby && odgadniete != haslo) {
  17. cout << "Proba " << (licznik + 1) << " z 10" << endl;
  18.  
  19. char litera;
  20. cin >> litera;
  21.  
  22. licznik++;
  23.  
  24. for (int i = 0; i < haslo.length(); i++) {
  25. if (haslo[i] == litera) {
  26. odgadniete[i] = litera;
  27. }
  28. }
  29.  
  30. if (odgadniete == haslo) {
  31. wygrana = licznik;
  32. }
  33. }
  34.  
  35. if (odgadniete == haslo) {
  36. cout << "Wygrales w probie: " << wygrana << endl;
  37. } else {
  38. cout << "Przegrales" << endl;
  39. }
  40.  
  41. return 0;
  42. }
Success #stdin #stdout 0.01s 5288KB
stdin
Standard input is empty
stdout
Liczba liter: 8
Proba 1 z 10
Proba 2 z 10
Proba 3 z 10
Proba 4 z 10
Proba 5 z 10
Proba 6 z 10
Proba 7 z 10
Proba 8 z 10
Proba 9 z 10
Proba 10 z 10
Przegrales