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;
}

remove the semicolon after main()

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

what do you mean by "arenot working"?

its not doing anything, after it ask for password2,

look at line 25. See that semicolon at the end??? That is causing an infinite do-nothing loop.

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.

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";
}

i don't know what you mean

//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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.