0

OK, I finally figured out command line arguments... my program is called prime, in the console i need to type "prime 7" and the program will tell me if its a prime or not.

heres my code:

```
#include <cstdlib>
#include <iostream>
#include <iomanip>
#include <stdlib.h>
using namespace std;
int main(int argc, char *argv[])
{
const unsigned long arraySize = 1000000;
bool a[arraySize];
unsigned long num1;
unsigned long num2;
unsigned long num3;
unsigned long counter = 0;
unsigned long primes = 0;
char z;
unsigned long answer = 0;
//Initializing elements to 1
for (int i = 0; i < arraySize; i++)
{
a[i] = 1;
}
// For array subscript 2, all elements beyond 2 in the array that
// are multiples of 2 will be set to zero ; for array subscript 3,
// all elements beyond 3 in the array that
// are multiples of 3 will be set to zero
for (int i = 2; i * i < arraySize; i++)
{
if (a[i])
for (int j = i + i; j < arraySize; j += i)
a[j] = 0;
}
// if user enters more than 3 numbers or 0 numbers
// program should output useful information
// and title and author
if ((argc > 4) || (argc == 1))
{
cout<<"This is Programming Assignment #5"<<endl;
cout<<"THE SIEVE OF ERATOSTHENES"<<endl;
cout<<"by Jeremy Rice"<<endl;
cout<<endl;
cout<<"Usage:"<<endl;
cout<<"\tprime num1 - determines if num1 is a prime"<<endl;
cout<<"\tprime num1 num2 - displays primes between numbers."<<endl;
}
// if user enters one number
// program should determine if that number is a prime
if (argc == 2)
{
if (a[argc] == 1)
{
num1 = strtoul(argv[]);
counter++;
cout<<"This is a prime number."<<endl;
}
else
cout<<"This is not a prime number."<<endl;
}
// if user enters 2 numbers
// program, should calculate the prime numbers
// between the two numbers
if (argc == 3)
{
}
return EXIT_SUCCESS;
}
```

heres the part I need help with

```
// if user enters one number
// program should determine if that number is a prime
if (argc == 2)
{
if (a[argc] == 1)
{
num1 = strtoul(argv[]);
counter++;
cout<<"This is a prime number."<<endl;
}
else
cout<<"This is not a prime number."<<endl;
}
```

what do I put in the num1 = strtoul(argv[]) to take the number entered in the command line prompt?