Number of paramaters

ERROR CHECK 1: NUMBER OF PARAMETERS:
NB: the name of the program counts as the 1st parameter (0th value in the array).
If the number of parameters is 1 then the program MUST print student ID string in CSV format as explained above.
If the number of parameters is 2 the output shall be 'P' which signals a Parameter error
If the number of parameters is 3 the operators shall be further tested as set out below.
If the number of parameters is more than 3, the output shall be 'P'.

is my code correct?

int main(int argc, char* argv[])
{
switch (argc)
{
//Error check 1
case 1:
cout << "3602151, s3602151@student.rmit.edu.au, Josh_wosh" << endl;
break;
case 2:
cout << "P" << endl;
break;
case 3:
{break; }
case 4:
cout << "P" << endl;
}
return 0;
}

I am unclear on what parameters even means and where to locate paramaters ? Is my code correct btw
Parameters are the values you pass into a function.

Here's a simple function:

1
2
3
4
int addOne ( int input)
{
  return ( input + 1);
}


Look at the first line.
int addOne ( int input)

The name of this function is addOne.
See that int at the start, before the name? That indicates that this function returns (i.e. gives back) an int.

See that bit in the brackets, ( int input ) ? That is the list of parameters. The parameters are what you must pass to the function when you use it. In this case, you can see there is one parameter; int input . The int is the type of the parameter, and input is the name that this parameter will have inside the function.


Now lets look at your code. There's one function here:
int main(int argc, char* argv[])
We can see that there are two parameters; int argc and char* argv[]. The first parameter is an int, and the second parameter is an array of char*.

The main function is a standard function, and the value of argc tells you how many char* there are in the array.

Your instructions are a little bit wrong; I think they don't actually mean the number of parameters; I think they mean the number of char* in the second parameter. Still, a little mistake in the wording is not something to get hung up on.

1
2
case 4:
cout << "P" << endl;

This is not correct.
If the number of parameters is more than 3, the output shall be 'P'.
It will miss any numbers > 4.

Better use the default case with an if statement.

Parameters are passed to your program like - your program.exe param1 param2 param3 etc.
Topic archived. No new replies allowed.