Code:
int main()
{
void extend(float [9], float[9] , float[9]);
You usually put function prototypes outside of main (at the beginning of the file, after all include's).
And if you pass an array as a parameter it's more flexible to add an additional parameter for the size of the array and then you use it instead of the hardcoded size:
Code:
void extern(float price[], float quantity[], float amount[], int size);
I prefer to match the prototype with the actual definition hence I've added the parameter names.
Code:
float price[9];
float quantity[9];
float amount[9];
printf("this program will accept 10 numbers and the quantity\n");
You know that you are only processing 9 numbers? :-)
I'm not sure if you already know about the preprocessor but if you use magic numbers in your code you should define them at the beginning of the file. Then there is only one place to change them:
Code:
#define SIZE 10
... // later in the program you use it everywhere you would have used the hardcoded value
for (i = 0; i < SIZE; i++)
...
Code:
for(j = 0; j < 9; j++)
{
amount[j] = price[j] * quantity[j];
}
for(h = 0; h < 9;h++)
{
printf("%.2f\n", amount[h]);
}
Since both for-loops have the same range you could merge them into one.
Originally Posted by
chumpp
My question is this the right way to go about putting the values in that new array. or any tips to make it more clean?
Looks fine for me.
Bye, Andreas