Hi, I have been working on this program for quite some time but I can't figure out what's wrong with it. The program compiles and this is the the output I get:
?Invalid number of arguments
Press any key to continue . . .
Can somebody please take a look at this program and give me some ideas?
Thanks!
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define TERMINAL -9
void swapArgs(int *a, int *b);
void divideArgs(int *a, int *b);
double *powerArgs(int *a, int *b);
int main(int argc, char **argv)
{
if (argc != 3)
{
printf("?Invalid number of arguments\n");
system("pause");
exit(1);
}
int parmA = atoi(argv[1]);
int parmB = atoi(argv[2]);
printf("A=%d, B=%d. ",parmA,parmB);
swapArgs(&parmA,&parmB);
printf("Swapped values A=%d, B=%d.\n",parmA,parmB);
parmA = atoi(argv[1]);
parmB = atoi(argv[2]);
printf("Quotient of %d / %d is ",parmA,parmB);
divideArgs(&parmA, &parmB);
printf("%d, remainder is %d\n",parmA,parmB);
parmA = atoi(argv[1]);
parmB = atoi(argv[2]);
printf("%d raised to the %d power is %.0lf\n",parmA,parmB,*powerArgs(&parmA, &parmB));
parmA = atoi(argv[1]);
parmB = atoi(argv[2]);
system("pause");
exit(0);
}
void swapArgs(int *a, int *b)
{
int temp;
temp = *a;
*a = *b;
*b = temp;
}
void divideArgs(int *a, int *b)
{
int temp;
temp = *b;
*b = *a;
*a = temp;
int remainder;
*a = *b / *a;
remainder = *a;
}
double *powerArgs(int *a, int *b)
{
static double result;
int i;
for ( i = 0, result = 1; i < *b; ++i )
{
result *= *a;
}
return &result;
}