fork download
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. int main() {
  7. string secret = "wisielec";
  8. string hidden = "";
  9.  
  10. for (int i = 0; i < (int)secret.length(); i++) {
  11. hidden += "_";
  12. }
  13.  
  14. int lives = 6;
  15.  
  16. cout << "=== WISIELEC ===" << endl;
  17.  
  18. while (lives > 0 && hidden != secret) {
  19. cout << "\nSlowo: " << hidden << endl;
  20. cout << "Pozostale proby: " << lives << endl;
  21.  
  22. cout << "Podaj litere: ";
  23. char letter;
  24. cin >> letter;
  25.  
  26. bool good = false;
  27.  
  28. for (int i = 0; i < (int)secret.length(); i++) {
  29. if (secret[i] == letter && hidden[i] == '_') {
  30. hidden[i] = letter;
  31. good = true;
  32. }
  33. }
  34.  
  35. if (good) {
  36. cout << "Dobrze!" << endl;
  37. } else {
  38. cout << "Zle!" << endl;
  39. lives--;
  40. }
  41. }
  42.  
  43. if (hidden == secret) {
  44. cout << "\nWygrales! Slowo: " << secret << endl;
  45. } else {
  46. cout << "\nPrzegrales! Slowo: " << secret << endl;
  47. }
  48.  
  49. return 0;
  50. }
Success #stdin #stdout 0.01s 5320KB
stdin
Standard input is empty
stdout
=== WISIELEC ===

Slowo: ________
Pozostale proby: 6
Podaj litere: Zle!

Slowo: ________
Pozostale proby: 5
Podaj litere: Zle!

Slowo: ________
Pozostale proby: 4
Podaj litere: Zle!

Slowo: ________
Pozostale proby: 3
Podaj litere: Zle!

Slowo: ________
Pozostale proby: 2
Podaj litere: Zle!

Slowo: ________
Pozostale proby: 1
Podaj litere: Zle!

Przegrales! Slowo: wisielec