Note that there are some explanatory texts on larger screens.

plurals
  1. POFunction: variable substitute
    text
    copied!<p>I'am having some trouble with the code below; I know it's rudimentary stuff for you more experienced coders, but this is my first time trying to code something in C so please bear with me. </p> <pre><code>#include &lt;stdio.h&gt; int main() { printf("This program, or function, substitutes one given number for another given number, and then places the former with the latter number. "); float y1 = 10; /* Assign value to variable 1*/ float y2 = 20; /* Assign value to variable 2*/ float y3 = 30; /* Assign value to variable 3*/ float y4 = 40; /* Assign value to variable 4*/ void sub( float *, float *, float *, float * ); /*declare function prototype*/ printf("\nThe numbers' given values before the aforementioned function: Number 1 = %f , Number 2 = %f\n , Number 3 = &amp;f , Number 4 = %f", y1, y2, y3, y4 ); sub( &amp;y1, &amp;y2, &amp;y3, &amp;y4 ); /*This is where the function, to move the numbers, is called */ printf("\nThe numbers' given values after the aforementioned function: Number 1 = %f , Number 2 = %f\n , Number 3 = &amp;f , Number 4 = %f", y1, y2, y3, y4 ); } void sub(float *z1, float *z2, float *n3, float *n4) { int z; int n; z = *z1; *z1 = *z2; *z2 = z; n = *n3; *n3 = *n4; *n4 = n; } </code></pre> <p>And the output is: </p> <pre><code>This program, or function, substitutes one given number for another given number, and then places the former with the latter number. The numbers' given values before the aforementioned function: Number 1 = 10.000000 , Number 2 = 20.000000 , Number 3 = &amp;f , Number 4 = 30.000000 The numbers' given values after the aforementioned function: Number 1 = 20.000000 , Number 2 = 10.000000 , Number 3 = &amp;f , Number 4 = 40.000000 </code></pre> <p>My question is: how do I change the code so that "number 3" substitutes itself just like the rest of the variables. </p>
 

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