This is a password check code.When I enter the right password,it outputs "access allowed!access allowed!"
When password is wrong,it outputs "try again!try again!".
Why is this happened? Thanks for any help!
Here is my code:
Code:
#include <iostream>
#include <string>
using namespace std;
int check(string x)
{
if(x=="pppp")
{
cout<<"access allowed!";
return 3;
}
else
{
cout<<"try again!";
return 1;
}
}
int main()
{
int i;
string pass;
do
{
cout<<"enter a password:";
cin>>pass;
check(pass);
i=check(pass);
}while(i==1);
}