1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
|
#include<iostream>
#include<vector>
using namespace std;
constexpr auto max_mistakes = 4;// C++11, can use const int instead for previous compiler versions //
int main(){
vector<int>password {0,0,0,1,1,0,1,0,1,0,1,0,0,1,0,0,1,0,1,0,0,1};
int digit = 0;
int mistakes = 0;
int i ;
for (int i = 0; i < password.size(); i++){
do{
cout<<"Please enter password character "<<(i+1)<<endl;
cin>> digit;
if(digit != password[i]){
mistakes++;
}
if (mistakes == max_mistakes){
break; // quits do-while loop //
}
}
while (digit != password[i]);
if(mistakes == max_mistakes){
cout<<"\nSorry, you've reached the max no of unsuccessful attempts"<<endl;
break; // quits for loop //
}
}
if(mistakes != max_mistakes){
cout<<"\nSuccess!!!"<<endl;
}
}
|