I remember my programming prof said that multiplication and division of pointers are not allowed. We have a seatwork that needs us to create a program that adds, subtracts, multiplies and divides two numbers using pointers.
This is my code in the main function:
float num1, num2, a, b, c, d;
printf("Enter a number: ");
scanf("%f", &num1);
printf("Enter another number: ");
scanf("%f", &num2);
a = add(&num1, &num2);
b = subtract(&num1, &num2);
c = multiply(&num1, &num2);
d = divide(&num1, &num2);
printf("Sum: %.2f\nDifference: %.2f\nProduct: %.2f\nQuotient: %.2f", a, b, c, d);
getch();
return 0;
This is my code for the add, subtract, multiply, and divide functions:
float add(float *x, float *y)
{
return *x+*y;
}
float subtract(float *x, float *y)
{
return *x-*y;
}
float multiply(float *x, float *y)
{
return *x * *y;
}
float divide(float *x, float *y)
{
return *x / *y;
}
My code runs and works but is it allowed?