Ok, so I had an assignment due a few days ago and I typed it all up myself without any help (pretty proud of myself at the time), but my instructor took off 4 out of 20 points because I didn't make it a void function.
Here is the code:
Code:
#include <stdio.h>
#define MAXARRAY 10
double extend(double[], double[], double[], int);
int main(){
double price[MAXARRAY] = {10.62, 14.89, 13.21, 16.55, 19.62, 9.47, 6.58, 19.32, 12.15, 3.99};
double quantity[MAXARRAY] = {4, 9.5, 6, 7.35, 9, 15.3, 3, 5.4, 2.9, 4.9};
double amount[MAXARRAY];
int i;
extend(price, quantity, amount, MAXARRAY);
for (i = 0; i < MAXARRAY; i++)
printf("The product of price %d and quantity %d is amount %5.2f\n", i+1, i+1, amount[i]);
return 0;
}
double extend(double price[], double quantity[], double amount[], int max){
int i;
double product;
double *p, *q;
p = price; q = quantity;
for (i = 0; i < max; i++)
amount[i] = *p++ * *q++;
amount[i] = product;
return (product);
}
The assignment doesn't say "extend" needed to be a void function. All it said is that the function "extend" needed to have three arrays passed to it.
This is what my instructor said:
extend should be a void function. You even call it as a void function! What do you think the variable product is doing in the function extend?
Not trying to call him out or anything, but just wondering why extend() needs to be a void function. The program works fine the way it is. It displays the product of the two arrays for each element just like the program asks.
Is it just sloppy coding?