Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <iostream>
- #include <string>
- using namespace std;
- int main()
- {
- string q;
- cout << "Enter the word for other player to guess" << endl;
- getline(cin, q);
- string copy = q;
- string Underscore;
- for (int i = 0; i != q.length(); i++) {
- if (q.at(i) == ' ') {
- Underscore += " ";
- }
- else {
- Underscore += "_";
- }
- }
- for (int i = 0; i != 50; ++i) {
- cout << endl;
- }
- string guess;
- int w =0;
- while (w<6) {
- if (w == 6) { cout << "You Lose! The word was: " << q << endl; break; }
- cout << Underscore << endl;
- cout << "There are " << q.length() << " letters with spaces" << endl;
- cout << "You have " << 6 - w << " more tries left" << endl;
- if (Underscore == q) {
- cout << "You win!" << endl;
- break;
- }
- cout << "Guess a letter or a word" << endl;
- getline(cin, guess);
- if (guess.length() > 1) {
- if (guess == q) {
- cout << "That's right, you win!" << endl;
- break;
- }
- else {
- cout << "wrong word " << endl;
- w ++;
- }
- }
- else if (copy.find(guess) != -1) {
- while (copy.find(guess) != -1) {
- Underscore.replace(copy.find(guess), 1, guess);
- copy.replace(copy.find(guess), 1, "_");
- }
- }
- else {
- cout << "That's wrong" << endl;
- w++;
- cout << endl;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement