Passing Parameters: Days of the Week Re-Write

I've read all the corresponding material in the book and have no clue what to do. Any help would be appreciated.

Here are the instructions:

Rewrite the program(The program that needs to be re-written is the code below) so that the input is passed on the command line when the program is executed. Do the work in functions. Be sure to check that the proper number of parameters were passed. If the proper number of parameters were not passed: display a usage statement to the standard error device, and exit the program with a non-zero return code.

I don't even know what it means by passes and parameters.

Thanks.

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

using namespace std;

int main(){
	char *days[] = {"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"};
	int num;
	cout << "Enter a number from 0 to 6: ";
	cin >> num;
        cout << endl;
    
	if(num >= 0 && num <= 6){
            cout << days[num] << endl;
	    cout << endl;

    system("PAUSE");
    return EXIT_SUCCESS;
  }
}
The book really had nothing about this?

You're going to need to employ another definition of main:
 
int main(int argc, const char* argv[]);

Where argc is the number of arguments and argv is a pointer to the first argument. Windows always sends the program's path as the first argument, so argc will always be >= 1. Any additional arguments sent will follow.

1
2
3
4
5
6
7
8
#include <iostream>
int main(int argc, const char* argv[])
{
	// Prints each argument on the command line.
	for(int i = 0; i < argc; ++i)
		std::cout << "argument " << i << ": " << argv[i] << std::endl;
	return 0;
}
Last edited on
Topic archived. No new replies allowed.