Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.30 KB | None | 0 0
  1. #include "stdafx.h"
  2.  
  3. #include <iostream>
  4.  
  5. #include <string>
  6.  
  7. using namespace std;
  8.  
  9.  
  10.  
  11. int main()
  12.  
  13. {
  14.  
  15. string q;
  16.  
  17. cout << "Enter the word for other player to guess" << endl;
  18.  
  19. getline(cin, q);
  20.  
  21. string copy = q;
  22.  
  23. string Underscore;
  24.  
  25. for (int i = 0; i != q.length(); i++) {
  26.  
  27. if (q.at(i) == ' ') {
  28.  
  29. Underscore += " ";
  30.  
  31. }
  32.  
  33. else {
  34.  
  35. Underscore += "_";
  36.  
  37. }
  38.  
  39. }
  40.  
  41. for (int i = 0; i != 50; ++i) {
  42.  
  43. cout << endl;
  44.  
  45. }
  46.  
  47. string guess;
  48.  
  49. int w =0;
  50.  
  51. while (w<6) {
  52.  
  53. if (w == 6) { cout << "You Lose! The word was: " << q << endl;   break; }
  54.  
  55. cout << Underscore << endl;
  56.  
  57. cout << "There are " << q.length() << " letters with spaces" << endl;
  58.  
  59. cout << "You have " << 6 - w << " more tries left" << endl;
  60.  
  61. if (Underscore == q) {
  62.  
  63. cout << "You win!" << endl;
  64.  
  65. break;
  66.  
  67. }
  68.  
  69. cout << "Guess a letter or a word" << endl;
  70.  
  71. getline(cin, guess);
  72.  
  73. if (guess.length() > 1) {
  74.  
  75. if (guess == q) {
  76.  
  77. cout << "That's right, you win!" << endl;
  78.  
  79. break;
  80.  
  81. }
  82.  
  83. else {
  84.  
  85. cout << "wrong word " << endl;
  86.  
  87. w ++;
  88.  
  89. }
  90.  
  91. }
  92.  
  93. else if (copy.find(guess) != -1) {
  94.  
  95. while (copy.find(guess) != -1) {
  96.  
  97. Underscore.replace(copy.find(guess), 1, guess);
  98.  
  99. copy.replace(copy.find(guess), 1, "_");
  100.  
  101. }
  102.  
  103. }
  104.  
  105. else {
  106.  
  107. cout << "That's wrong" << endl;
  108.  
  109. w++;
  110.  
  111. cout << endl;
  112.  
  113. }
  114.  
  115. }
  116.  
  117. return 0;
  118.  
  119. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement