I am suppose to create a small program that uses command line arguments. Its suppose to be executable as pgm1 -c, if 'c' is 'o' then its suppose to output the sum of odd integers 1-100, if 'c' is 'e' then its suppose to output the sum of even integers 1-100. If c is any other char, it should print an error message. Here is my code but when i try to use a command line argument when i run it nothing happens and i just get another prompt. Could somebody pls point me in the write direction. Thanks a lot.
#include<iostream>
using namespace std;
int sumOdd();
int sumEven();
int main(int argc, char *argv[])
{
switch(argc)
{
case1: break;
case2: if(strcmp(argv[1], "-o") == 0) cout<<"The sum of odd numbers from 1-100 is "<<sumOdd()<<endl;
else if(strcmp(argv[1], "-e") == 0) cout<<"The sum of even numbers from 1-100 is "<<sumEven()<<endl;
else cout<<"Invalid Argument"<<endl;
default:;
}
return 0;
}
int sumOdd()
{
int total = 0;
for(int i = 1; i < 100; i + 2)
total = total + i;
return total;
}
int sumEven()
{
int total = 0;
for(int i = 0; i < 100; i + 2)
total = total + i;
return total;
}
