dirtydevil123

Hangman Game

Jul 3rd, 2021 (edited)
250
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.78 KB | None | 0 0
  1. #include <iostream>
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.    string word[] = { "award", "await", "attend", "bubble", "coding", "spring", "mango", "night", "orange", "reward"};
  8.    string m,n;
  9.    int x;
  10.    char c;
  11.    srand(time(0));
  12.    m=word[rand()%10];
  13.    n=m;
  14.    x=m.length();
  15.    char a[x];
  16.    for(int i=0; i<x;i++){
  17.     m[i]='-';
  18.    }
  19.    cout<<m<<endl;
  20.    for(int i=0;i<x+2;i++){
  21.  
  22.     cout<<"Guess a letter: ";
  23.     cin>>c;
  24.     for(int j=0;j<x;j++){
  25.         if(n[j]==c){
  26.             m[j]=c;
  27.  
  28.         }
  29.     }
  30.  
  31.     cout<<m<<endl;
  32.  
  33.    if(m==n){
  34.     cout<<"Correct guess!"<<endl;
  35.     break;
  36.    }
  37.    }
  38.    if(m!=n){
  39.     cout<<endl;
  40.  
  41.    cout<<"Guessed wrong"<<endl;
  42.    cout<<endl;
  43.    cout<<"Word was : "<<n<<endl;
  44.    }
  45.     return 0;
  46.  
  47. }
  48. kk
  49.  
Add Comment
Please, Sign In to add comment