am wrting a password program in c++ but its not working, some error, says "missing function header (old-style formal list?)"

#include "stdafx.h"
#include <iostream>

using namespace std;

int main();
{


    int password = 1234;
    int password2 = 0000;
    int x = 0;



    cout << "Please enter the password2";
    cin >> password2;




    {


        while (password!=password2);


        cout << "wrong password";
        cout << "Please enter password2 again";
        cin >> password2;
        x++;
        for ( ;x>2; );

        cout<<"Too many tries";
        cout<<"program wil now exit";
        exit (0);
    }
    if (x>3)
        cout<<"Access Granted";
    return 0;
}

Edited 3 Years Ago by mike_2000_17: fixed formatting

guess what the program runs but only the first part that shows up "cout<<"Please enter the password2"", and the other codes arenot working

its not doing anything, after it ask for password2,

Edited 3 Years Ago by Daneil

The same is true for line 32. Both loops are infinite do-nothing loops. I'm not sure what you tried to do, I can't really understand what's going on.

Your for statement has some problems...too many semicolons.....no { } 's

Maybe an "if" statement would be better.

Edited 3 Years Ago by paulfecht: none

Too many problems to list. Before do coding, write a plan of what you want to do. It will help you coding clearly.

I do not know why there is a curly brace before the while loop :S But your while loop can be like this:

while(password!=password2){
        x++;
        cout << "wrong password";
        cout << "Please enter password2 again";
        cin >> password2;

        if(x>2)//use if statement to check if attempts crossed the limit
        {
        cout<<"\nToo many tries\n";
        cout<<"Program wil now exit\n";
        exit(0);
        }
    }

Well in order for "Access Granted" to happen password needs to be equal to password2.

Thus the condition of the if statement at line 38 needs to be:

if(password=password2){
    cout << "Access Granted";
}

//limit entry of password2 to 2 tries
tries equal zero
while tries less than 2
start body of while loop
enter password2
if password2 equals password
start body of if statement
tries equals three
end body of if statement
else
start body of else statement
display error statement
end vody of else statement
increment tries
end body of while loop
//determine while loop stopped
if tries equals 2
start body of if statement
exit program
end body of if statement
else
start body of else statement
display statement of success
end body of else statement

This article has been dead for over six months. Start a new discussion instead.