@sjohns10maine/

command line arguments

C++

No description

fork
loading
Files
  • main.cpp
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
/*Write a program that takes three integers on the command line and print the sum
If the user gives the wrong number of arguments, print “invalid input”



Tip: if you get an error while using atoi(), trying adding .c_str() at the end of your string variable name */

#include <cstdlib>// atoi 
#include <iostream>

using namespace std;

int main(int argc, char** argv) {
     
    if (argc < 4 || argc > 4){
        cout << "invalid input";
    }
   
    cout << argc << endl;
    cout << argv[0] << endl;
    cout << atoi (argv[1]) + atoi(argv[2]) + atoi (argv[3]);
    return 0;
}