Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The error is pretty clear, you're not calling the function the way it's supposed to be. The function takes 4 parameters, and you are only passing one.</p> <p>But that is only your FIRST mistake. The SECOND, is that the function arguments as they are declared right now, will make a local copy of the parameters:</p> <pre><code>double convertTemp (double tempF, double tempR, double tempC, double tempK); </code></pre> <p>This means that inside the body of the function, changes on any of these variables will not propagate to the variables declared in main which you used to call <code>convertTemp()</code>. What I'm saying is at the time the function is called, another 4 variables are created on the stack and their values are copied from the variables you sent to the function. </p> <p>There are two approaches to solve this problem:</p> <ul> <li><p><strong>The first</strong>, a little more complex to understand if you don't know nothing about pointers. On this approach, in order to modify the original variables of main, you need to change your function signature to receive memory pointers instead:</p> <p>void convertTemp (double* tempF, double* tempR, double* tempC, double* tempK);</p></li> </ul> <p>and the body of function needs to change too, in order to be consistent with the prototype declared in the beginning of the file:</p> <pre><code>void convertTemp (double* tempF, double* tempR, double* tempC, double* tempK) { //Statements *tempR = (*tempF - 32) + 491.67; *tempC = (*tempF - 32) * 100/180; *tempK = *tempC + 273.16; } </code></pre> <p>Note that the new function signature does not return any value (ie. <em>void</em>). This is not necessary since you will be operating directly on the variables passed by <code>main()</code>.</p> <p>On <code>main()</code>, you should call the function like:</p> <pre><code>fahrenheit = obtainTemp(); convertTemp(&amp;fahrenheit, &amp;rankine, &amp;celsius, &amp;kelvin); </code></pre> <ul> <li><strong>The second approach</strong>, since you are a beginner this is probably going to be easier for you to understand, is to declare 3 functions, one for each conversion you need to do:</li> </ul> <p><code></code></p> <pre><code>double convertR(double value) { return (value - 32) + 491.67; } double convertC(double value) { return (value - 32) * 100/180; } double convertK(double value) { return value + 273.16; } </code></pre> <p>Then on <code>main()</code>, you would call them like:</p> <pre><code>fahrenheit = obtainTemp(); rankine = convertR(fahrenheit); celsius = convertC(fahrenheit); kelvin = convertK(fahrenheit); printResult(fahrenheit, rankine, celsius, kelvin); </code></pre>
 

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