Note that there are some explanatory texts on larger screens.

plurals
  1. POPassing modified array values back to main function in C
    primarykey
    data
    text
    <p>Sorry if the title is still ambiguous.</p> <p>I'm doing this assignment for school and below are my defined function prototypes, the main function and the change_array function.</p> <p>The overall objective of this program is to allow users to input 5 different numbers and be stored into an array. Then what the change_array function does is to double (multiply by 2) any numbers that are below 10, however, it is currently not doing what it is intended to do. I'm really stuck, so I was wondering if anyone can point out my mistakes. I'm not asking for an exact answer, I just need some pointers and guidance. </p> <p>What is going wrong is that the change_array function is not changing any of the values given by the users. So for example, if the user inputs, "3, 5, 6, 12, 32", the output of my program is still "3, 5, 6, 12, 32". But what I really want is, "6, 10, 12, 12, 32" after the arrays are passed back from the change_array function.</p> <p>EDITED with complete program:</p> <pre><code>#include &lt;stdio.h&gt; #define SIZE 5 void fill_array(double x[], int s); void change_array(double x[], int s); void print_array(double x[], int s); main() { double x[SIZE]; fill_array(x, SIZE); printf("The array is as: \n"); print_array(x, SIZE); change_array(x, SIZE); printf("After change, the array is: \n"); print_array(x, SIZE); } void fill_array(double x[], int s) { int i=0; printf("Please input 5 Non-Negative double numbers\n"); for (i=0; i&lt;s; i++) { printf("Number %d: ", i+1); scanf("%d", &amp;x[i]); printf("\n"); } } void change_array(double x[], int s) { int i=0; for (i=0; i&lt;s; i++) { if (x[i] &lt; 10) { (x[i] = (x[i] * 2)); } } } void print_array(double x[], int s) { int i=0; for (i=0; i&lt;s; i++) { printf("%ld \t", x[i]); } printf("\n"); } </code></pre> <p>My code is written in C.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload