Write a program that runs from the command line and takes a
Write a program that runs from the command line and takes a number and a name as an input from the user. It then says hello to it as many times as the user specified number. For example, the command line should show something like this: Show program in C++ Stange_things_happen.exe student 1. Hello student, 2. Hello student, 3. Hello student, 4. Hello student,
Solution
#include <iostream>
#include <stdlib.h> /* atoi */
using namespace std;
int main(int argc, char **argv)
{
if( argc < 2)
{
cout<<\"Enter number number and name as command line argument\"<<endl;
return -1;
}
for(int i = 0 ; i < atoi(argv[1]) ; i++)
{
cout << \"Hello \"<< argv[2]<<\",\"<<endl;
}
return 0;
}
