Couple of errors in my code

I'm constructing a basic Battleships game, and I keep receiving errors. Here is my code (it's not very long)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <iostream>
#include <cstdio>
#include <cstdlib>

using namespace std;

int main (int nNumberofArgs);
{
    
    int placeAirCarr
    int placeBatt
    int placeDest
    int placeSub
    int placePatrol
    
    cout << "Welcome to Battleships!" << endl;
    
    system ("PAUSE");
    
    cout << "Please enter a value between 1 and 25 to place the Aircraft Carrier" << endl;
    cin >> placeAirCarr
return 0;
}



And the error messages;
8 C:\..main.cpp expected unqualified-id before '{' token
8 C:\..main.cpp expected `,' or `;' before '{' token


I've had a browse online and I've tried using others' advice but it doesn't seem to resolve the problem in my code.

Many thanks
By glancing at your code it would seem that you have misplaced a few semicolons ( ; ).

int main (int nNumberofArgs); //<-- delete this semicolon

Only function declarations have semicolons at the end, function definitions do not.

int placeAirCarr //<-- add a semicolon here

cin >> placeAirCarr //<-- add a semicolon here

Additionally after each "statement" (not sure how else to refer to it), requires a semicolon.

The corrected code would look like this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
int main (int nNumberofArgs)    //<-- semicolon removed from here
{
    
    int placeAirCarr;     //<-- semicolon added here
    int placeBatt;        //<-- semicolon added here
    int placeDest;        //<-- semicolon added here
    int placeSub;         //<-- semicolon added here
    int placePatrol;      //<-- semicolon added here
    
    cout << "Welcome to Battleships!" << endl;
    
    system ("PAUSE");
    
    cout << "Please enter a value between 1 and 25 to place the Aircraft Carrier" << endl;
    cin >> placeAirCarr;    //<-- semicolon added here
    return 0;
}


Also I see that you have tried to take in some command line parameters (nNumberofArgs), you might also need the "argv" to actually access the parameters passed to the application:

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

You might benefit from doing some more tutorials before you continue, this site has some really good ones, you can find them here: http://www.cplusplus.com/doc/tutorial/

Hope this helps!
Thank you very much for your help :) I see now that the errors don't specify a specific location where a semi-colon should/shouldn't be, just that there has to/doesn't have to be one before a certain point (in my opinion, rather like a person saying that they saw a marathon runner cross the line but not telling you whether it was five minutes or five hours ago!).

ahh I didn't know "argv" was necessary for that, again, thank you :)

Yes I've only been using the tutorials for reference so far...looks like I could do with reading them properly ;P

Kind regards,
Topic archived. No new replies allowed.