Thanks, DaWei.
I played with the code and it now compiles and runs like it should.
Code: c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void PrintUsage(void);
int main(int argc, char* argv[]) {
/* holds the sum */
double dAnswer = 0.0;
/* parse input */
switch(argc) {
/* no input parameters */
case 1:
PrintUsage();
break;
/* only 1 parameter passed */
case 2: {
int inplen = strlen(argv[1]);
char input[inplen];
strcpy(input, argv[1]);
/* check for usage switches */
if ( !strcmp(input, "-help") || !strcmp(input, "help") || !strcmp(input, "?") || !strcmp(input, "/?") )
/* call PrintUsage function if a valid switch is present */
PrintUsage();
else
/* return the single value if it is numeric */
printf("%.2f\n", atof(argv[1]));
}
break;
/* multiple parameters passed; calculate the sum */
default: {
/* a counter */
int iCount = 0;
/* cycle through input, summing the values */
for (iCount = 1; iCount < argc; iCount++) {
dAnswer += atof(argv[iCount]);
}
/* print sum to the screen */
printf("%.2f\n", dAnswer);
}
}
/* end program */
return 0;
}
void PrintUsage(void) {
/* code removed to conserve space */
}