Pointers and functions help
I'm currently a student taking an online C programming class, and this board has been a lifesaver. Well, it looks like I need your guys help again.
Was given a fully written code that I needed to write functions for, and I handled the first two alright (forgive any poorly scripted coding. I'm trying my best), but the compiler keeps halting on the third. I'm sure it's something simple, but I can't figure it out. Any help would be appreciated.
Code:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int swapArgs(int *a,int *b);
int divideArgs(int *a, int *b);
double powerArgs(int *a, int *b);
/* MAIN */
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]);
/* Part A: Swap the values. Value in parmA is moved to parmB and vice versa */
/* Reset the original values after we print the result */
printf("A=%d, B=%d. ",parmA,parmB);
swapArgs(&parmA,&parmB);
parmA = atoi(argv[1]);
parmB = atoi(argv[2]);
/* Part B: Divide parmA by parmB. Put the quotient in parmA, remainder in parmB */
/* Reset the original values after we print the result */
printf("Quotient of %d / %d is ",parmA,parmB);
divideArgs(&parmA, &parmB);
parmA = atoi(argv[1]);
parmB = atoi(argv[2]);
/* Part C: Raise parmA to the power of parmB. Return pointer to the result */
/* Reset the original values after we print the result */
printf("%d raised to the %d power is ",parmA,parmB);
printf("%.0lf \n", *powerArgs(&parmA, &parmB);
return 0;
}
int swapArgs(int *a, int *b)
{
int tempA = *a, tempB = *b;
*a = tempB;
*b = tempA;
printf("Your first number is now %d, and your second is now %d\n", *a, *b);
*a = tempA;
*b = tempB;
}
int divideArgs(int *a, int *b)
{
int tempA = *a, tempB = *b;
double divisor = *a / *b;
*a = (long) divisor;
*b = divisor - *a;
printf("%d, with the remainder being %f\n", *a, *b);
*a = tempA;
*b = tempB;
}
double powerArgs(double *a, double *b)
{
double powerArgs = pow ((double) *a, (double) *b);
return powerArgs;
}