does anyone know the code to output "Wrong password final try" on a 2nd unsuccessful password input? and then make the program go back to the default start position for the program below?

#include <cstdio>
#include <cstdlib>
#include <iostream>
using namespace std;

static const int password=1705898;

int main()
{
	int secondnumber;
    {
		cout << "Enter Password: ";
          cin >> secondnumber;
		  
		  if (password == secondnumber)
		  {
               cout << "Welcome Matthew ";
          }
          else
          {
               cout << "Password Rejected ";
		  }		
}
system ("PAUSE");
return 0;
}

put your code in a loop:

loop while tries <= 3
//your code

if tries == 2 
    show: Last change!     

end loop

[edit] too slow for iamthwee

DO NOT pm me for help anymore.

With that said, let me give you a sample-program

for (int count=1; count <=3; count++)
{
    cout << "This is pass: " << count << endl;
    if (count == 2) 
    {
        cout << "This was your second try" << endl;
    }
}

Try it out and see if you can understand how this will be usable for your own code

it doesnt work!

Well mark,
niek_e is only giving you an example on how it is done. You can try experimenting in that code to get the answer though.

Something like this will work out fine.

#include <iostream>

using namespace std;

static const int password=1705898;

int main()
{
	int secondnumber;
	for(int a=1;a<=3;a++)
    {
		cout << "Enter Password: \n";
          cin >> secondnumber;
          
		  
		  if (password == secondnumber)
		  {
               cout << "Welcome Matthew ";
               cin.get();
               return 0;

          }
          else if (a==2)
          {
          cout<<"Password Rejected Final try";
          }
          else
          {
               cout << "Password Rejected ";
		  }		
    }
cin.get();
}
This article has been dead for over six months. Start a new discussion instead.