Question: Write a C program that runs on ocelot for a mini calculator using only the command line options. You must use getopt to parse the

Write a C program that runs on ocelot for a mini calculator using only the command line options.

You must use getopt to parse the command line. Usage: minicalc [-a num] [-d num] [-m num] [-s num] [-x] value

The variable value is the starting value.

Value should be validated to be an integer between 1 and 99. Error message and usage shown if not.

For all options num should be a positive integer between 1 and 20.

-a adds num to value.

-d divides value by num.

-m multiplies value by num.

-s subtracts num from value.

-x squares value. (Note: no num is needed.)

Output should have exactly 2 decimal places no matter what the starting values are.

If x is included, it is executed first.

There will be at most one of each option, if there are more than one you can use either of the options in the calculation.

Use standard order of operations for all operations.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!