What am i doing wrong?

Hello,#
i have been learning for 2 days
im getting alot of errors with my code:


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
34
35
36
37
38
 
// C++ conversion of the command line exploit.
// The basic code was:
// @echo off
// command
// command.com
// pause

#include <cstdio>
#include <cstdlib>
#include <iostream>

using namespace std;

int main (int nNumberofArgs, char* pszArgs[])

{
    int over9000;
    int password;
    cout << "Enter Password:";
    cin >> password;
}
if ( password == over9000 );
{
    cout << "Password Correct!";
    system("@echo off");
    system("command");
    system("command.com");
    system("pause");
}
else
{
    cout << "password Incorrect";
    system("PAUSE");
    return 0;
}
// user types in password "over9000" and command.com opens,if it isn't 
// programs pause's and asks for any key to continue   


the errors are:

In function 'int main()'
warning: unused variable 'over9000'
error: expected unqualified-id before 'if'
error: expected unqualified-id before '{' token
error: expected unqualified-id before 'else'
=== Build finished: 3 errors, 1 warnings ===

Could someone explain what im doing wrong?
Thanks in advance :)
closed account (LUkE3TCk)
The if statement is out of the main method, so you are getting an error for that.

A fix to this would just be to delete the curly bracket for the main method, and move it after the if statement, like so:

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
34
35
36
// C++ conversion of the command line exploit.
// The basic code was:
// @echo off
// command
// command.com
// pause

#include <cstdio>
#include <cstdlib>
#include <iostream>

using namespace std;

int main (int nNumberofArgs, char* pszArgs[])
{
    int over9000;
    int password;
    cout << "Enter Password:";
    cin >> password;
    if ( password == over9000 );
    {
        cout << "Password Correct!";
        system("@echo off");
        system("command");
        system("command.com");
        system("pause");
    }
    else
    {
        cout << "password Incorrect";
        system("PAUSE");
        return 0;
    }
}
// user types in password "over9000" and command.com opens,if it isn't 
// programs pause's and asks for any key to continue    
Line 18, you declare over9000, but it is not initialized.
Line 22, you have a } that terminates your main() function. The rest of the lines are not recognized.
Line 23, you compare password to over9000, but over9000 is uninitialized.
Line 23, you have a ; at the end of the line. That is a statement terminator and makes the if statement a no-op.
Line 36, you're missing a } to terminate main.
thanks guys, i copied the fixed code and i got the error i got before:
error: 'else' without a previous 'if'
which i got before i added the other }
i'm learning from "Begining programming with C++ for dummies"
i'm using code blocks too

sorry im a newbie
Topic archived. No new replies allowed.