Program description:

To be edited...

Your code:

Make file

minicalc: minicalc.c
	gcc -o minicalc minicalc.c -I.
clean:
	rm *.o *.err

.c File

#include <stdio.h>
#include <stdlib.h>


int main(int argc, char **argv){

	extern char *optarg;
	extern int optind;
	int c, err = 0; 
	int dflag=0, mflag=0, aflag=0, eflag = 0, sflag=0;
        int dnum=0, mnum=0, anum=0, snum=0;
	static char usage[] = "usage: minicalc [-a num] [-d num] [-m num] [-s num] [-e] value\n";

        /*Checks usage and inputs and stores arithmetic values into variables*/
	while ((c = getopt(argc, argv, "a:d:m:es:")) != -1)
		switch (c) {
		case 'd':
                        dflag = 1;
			dnum = atoi(optarg);
			break;
		case 'm':
			mflag = 1;
                        mnum = atoi(optarg);
			break;
		case 'a':
			aflag = 1;
                        anum = atoi(optarg);
			break;
		case 'e':
			eflag = 1;
			break;
		case 's':
			sflag = 1;
                        snum = atoi(optarg);
			break;
		case '?':
			err = 1;
			break;
		}
	if ((optind+1) > argc) {	
		/* need at least one argument (change +1 to +2 for two, etc. as needeed) */

		printf("optind = %d, argc=%d\n", optind, argc);
		fprintf(stderr, "%s: missing value\n", argv[0]);
		fprintf(stderr, usage, argv[0]);
		exit(1);
	} else if (err) {
		fprintf(stderr, usage, argv[0]); /*Usage message if error*/
		exit(1);
	}
	/* see what we have */
	printf("dflag = %d\n", dflag);
	printf("mflag = %d\n", mflag);    
	printf("aflag = %d\n", aflag);
	printf("eflag = %d\n", eflag);
	printf("sflag = %d\n", sflag);

        printf("dnum = %d\n", dnum);
	printf("mnum = %d\n", mnum);    
	printf("anum = %d\n", anum);
	printf("snum = %d\n", snum);

        double value = atoi(argv[optind]); /*Saves value input into value variable*/

        /*Checks if input value is between 1 and 99*/
	if(value < 1 || value > 99){ 
		printf("Input value needs to be between 1 and 99\n"); /*Error message for num not between 1 and 99*/
		fprintf(stderr, usage, argv[0]); /*Usage message*/
		exit(1);
	} else {
		printf("value = %.0f\n", value); /*Shows what the value input is*/
	}

        /*Squares value*/
        if(eflag == 1){
		value *= value;
	}
	/*Mulitplies value by mnum*/
	if(mflag == 1){
		value *= mnum;
	}
	/*Divides value by dnum*/
	if(dflag == 1){
		value /= dnum;
	}
	/*Adds anum to value*/
	if(aflag == 1){
		value += anum;
	}
	/*Subtracts snum from value*/
	if(sflag == 1){
		value -= snum;
	}

        printf("Result is %.2f\n", value); /*Outputs result */
  
  exit(0);
}

All the assignments will be posted. Subscribe for more! :)