What exactly does this mean??

Your program must determine the user-specified lower bound and upper bound by using command-line arguments. You will need to use the strtoul() function (from the cstdlib header) to convert command-line arguments to int values.

Dani AI

Generated

: the assignment just means the two bounds are supplied when the program is started (not typed later). has the basic idea of how arguments reach your program, and pointed to useful references. Below are practical, concrete points to make your implementation robust and easy to test.

Always validate the arguments first. Check the count of arguments and show a short usage message when it’s wrong. Choose the correct integer type for the task (signed vs unsigned) and be explicit about what the program accepts. Use a conversion routine that (a) signals overflow/underflow, and (b) can tell you whether the whole string was valid numeric text — that lets you detect stray characters like "123abc" or accidental spaces. After conversion, check for range errors and whether the lower bound is actually less-than-or-equal-to the upper; decide whether to swap them automatically or treat that as an input error.

Quick checklist to debug surprises: confirm what your IDE is actually passing as program arguments (IDE run settings often differ from a shell), print the raw argv values while testing, compile with all warnings enabled to catch obvious mistakes, and test edge cases (negative input if unsigned expected, zero, very large numbers, non-digit strings). If you follow a consistent error-reporting pattern (clear message + nonzero exit code) automated tests and graders will understand failures faster.

Small skeleton to start (fill the parsing/validation where noted):

int main(int argc, char* argv[]) {
    if (argc != 3) {
        std::fprintf(stderr, "Usage: %s LOWER UPPER\n", argv[0]);
        return 1;
    }
    // parse and validate argv[1], argv[2] here
}

If the instructor specified a particular conversion routine, use that and add the checks above; otherwise pick a routine that gives you an end-pointer and an overflow indicator so you can reliably validate input.

Recommended Answers

All 2 Replies

"User-specified" means you must be able to read "command line arguments" and convert the arguments to integers.

The program will be run with a command similar to: progname lowval highval Then in the code grab lowval & highval (which will be c-strings) and use them.

If it's the use of command line arguments that's giving you pause, here's a couple links with helpful information:


http://www.cprogramming.com/tutorial/lesson14.html

Textbooks seem to generally ignore this topic.
Val

(Sorry, AD, it's early and I didn't see that your comments included a similar link.)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.