Advertisement
jayinnn1

Untitled

Jun 12th, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.62 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. int main(){
  4.     srand(time(0));
  5.     char randarr[10] = {'0','1','2','3','4','5','6','7','8','9'};  
  6.     random_shuffle(randarr, randarr+10);   
  7.     string ans, guess;
  8.     for(int i=0;i<4;i++){
  9.         ans += randarr[i];
  10.     }
  11.     cout << "The answer is:" << ans << endl;
  12.     int a, b;
  13.     while(1){
  14.         a = b = 0;
  15.         cout << "Your guess:";
  16.         cin >> guess;
  17.         cout << endl;
  18.         if(ans == guess) break;
  19.         for(int i=0;i<4;i++){
  20.             if(guess[i] == ans[i]) a++;
  21.             else if(ans.find(guess[i]) != string::npos) b++;
  22.         }
  23.         cout << a << "A" << b << "B" << endl;
  24.     }  
  25.     cout << "Your guess is right!!!" << endl;  
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement