Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Lots of things are wrong with your code, but there is a single root cause to this - a misunderstanding of how the <code>return</code> statement works.</p> <p>You have a function with multiple <code>return</code> statements. It appears that you think that all of these statements would execute; that assumption is incorrect. Only the first <code>return</code> statement reached in a function is executed; the remaining ones are ignored.</p> <p>Moreover, you appear to imply that <code>return</code> statement would influence variables in the caller automatically; it wouldn't. In order to modify a variable in the caller, the caller itself needs to assign the returned value.</p> <p>If you need your function to return multiple values, you need to change the approach: it should take multiple arguments by reference, and modify them, like this:</p> <pre><code>void Calculation(long double x, long double y, long double &amp;sum, long double &amp;difference, long double &amp;product, long double &amp;quotient) { sum = x + y; difference = x - y; product = x * y; quotient = x / y; } </code></pre> <p>You also need to change the prototype declaration of <code>Calculation</code>, like this:</p> <pre><code>void Calculation(long double x, long double y, long double &amp;sum, long double &amp;difference, long double &amp;product, long double &amp;quotient); </code></pre> <p>Call <code>Calculation</code> like this:</p> <pre><code>Calculation(a, b, sum, difference, product, quotient); </code></pre> <p>This will solve your compilation issue, and the code will run correctly.</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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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