command-line arguments
the module 5 mastery check said:
i forget how it worked so i looked back. after reading that part of the chapter again i still didn't understand it so i made the example program to make it more clear. but the program didn't work. and the last system pause is never executed.
1 can someone explain to me how command-line arguments work and what they do?
2 can someone tell me why the code doesn't work.
the code of the example program that doesn't work:
8. Write a program that requires a password that is specified on the command line. Your program doesn’t have to actually do anything except report whether the password was entered correctly or incorrectly.
1 can someone explain to me how command-line arguments work and what they do?
2 can someone tell me why the code doesn't work.
the code of the example program that doesn't work:
Code:
#include <iostream>
#include <cstdlib>
using namespace std;
int main(int argc, char *argv[])
{
double a, b;
if (argc!=3)
{
cout <<"usage: add num num" <<endl;
system("pause");// added this one so the screen wouldn't disappear
return 1;
}
a = atof(argv[1]);
b = atof(argv[2]);
cout << a+b;
system("pause");
return 0;
}



