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 proby = 10;
  11. int licznik = 0;
  12. int wygrana = 0;
  13.  
  14. cout << "Liczba liter: " << haslo.length() << endl;
  15.  
  16. while (proby > 0 && odgadniete != haslo) {
  17. cout << "Proby: " << proby << endl;
  18.  
  19. char litera;
  20. cin >> litera;
  21.  
  22. licznik++;
  23.  
  24. bool traf = false;
  25.  
  26. for (int i = 0; i < haslo.length(); i++) {
  27. if (haslo[i] == litera) {
  28. odgadniete[i] = litera;
  29. traf = true;
  30. }
  31. }
  32.  
  33. if (!traf) {
  34. proby--;
  35. }
  36.  
  37. if (odgadniete == haslo) {
  38. wygrana = licznik;
  39. }
  40. }
  41.  
  42. if (odgadniete == haslo) {
  43. cout << "Wygrales w probie: " << wygrana << endl;
  44. } else {
  45. cout << "Przegrales" << endl;
  46. }
  47.  
  48. return 0;
  49. }
Success #stdin #stdout 0.01s 5320KB
stdin
Standard input is empty
stdout
Liczba liter: 8
Proby: 10
Proby: 9
Proby: 8
Proby: 7
Proby: 6
Proby: 5
Proby: 4
Proby: 3
Proby: 2
Proby: 1
Przegrales