#include #include #include using namespace std; void Usage(char* argv) { cout << "Usage " << argv << ":" << endl; cout <<"\t-h, --HIGH\t\t Set high value, needs int" << endl; cout <<"\t-l, --LOW\t\t Set low value, needs int" << endl; cout <<"\t-s\t\t Set skip value, needs int" << endl; cout <<"\t?\t\t Help, this message" << endl; cout << endl; return; } int main(int argc, char * argv[]) { int lowerLimit = 1, upperLimit = 10, skipFactor = 1; int i; i = 1; while (i < argc) { if (strcmp(argv[i], "?") == 0) { Usage(argv[0]); i++; } else if (strcmp(argv[i],"-s")== 0) { i++; if (i < argc) { skipFactor = atoi(argv[i]); if (skipFactor == 0 ) { cout << "Skip value can not be 0" << endl; skipFactor = 1; } } else { cout << "\t-s requires an additional integer argument" << endl; } i++; } else if (strcmp(argv[i],"-l") == 0 or strcmp(argv[i],"--LOW")==0) { i++; if (i < argc) { lowerLimit = atoi(argv[i]); } else { cout << "\t-l requires an additional integer argument" << endl; } i++; } else if (strcmp(argv[i],"-h") == 0 or strcmp(argv[i],"--HIGH")==0) { i++; if (i < argc) { upperLimit = atoi(argv[i]); } else { cout << "\t-h requires an additional integer argument" << endl; } i++; } else { cout << "Unknown Option " << argv[i] << endl; Usage(argv[0]); i++; } } if ((lowerLimit > upperLimit and skipFactor > 0 ) or (lowerLimit < upperLimit and skipFactor < 0) ) { cout << " sorry no infinate loops " << endl; } else { i = lowerLimit; if (skipFactor > 0) { while (i <= upperLimit) { cout << i << " " ; i += skipFactor; } } else { while (i >= upperLimit) { cout << i << " " ; i += skipFactor; } } cout << endl; } return 0; }