Untitled

 avatar
unknown
plain_text
a month ago
1.4 kB
2
Indexable
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <ctime>
using namespace std;
int main() {
    vector<string> fruits = {"molle", "dardhe", "banane", "qershi", "ftua", "shalqi"};
    srand (time(0));
    string wordToGuess = fruits[rand() % fruits.size()];
    string guessedWord(wordToGuess.length(),'_');
    int attemps = 6;
    cout<<"Loja Hangman"<<endl;
    while (attemps > 0){
        cout<< "Fjala:";
        for(char c : guessedWord){
            cout<<c<<"";
        }
        cout<<endl;
        cout<<"Perpjekje te mbetura:"<<attemps<<endl;
        cout<<"Shkruani nje shkronje:";
        char guess;
        cin>>guess;
        bool found = false;
        for (size_t i = 0; i< wordToGuess.length();  i++){
            if (wordToGuess[i] == guess && guessedWord[i] == '_'){
                guessedWord[i] = guess;
                found = true;
            }
        }
        if (found){
            cout<<"Sakte! Shkronja"<<guess<<"eshte pjese e fjales."<<endl;
              } else{
                  cout<<"Gabim! Shkronja"<<guess<< "Nuk eshte pjese e fjales."<<endl;
                  attemps --;
              }
              if (guessedWord == wordToGuess){
                  cout<<"Urime! Ju gjetet fjalen:"<< wordToGuess<<endl;
                  break;
              }
    }
    if (attemps ==0){
        cout<<"Ju humbet! Fjala ishte:"<<wordToGuess<<endl;
    }
    
   

    return 0;
}
Leave a Comment