Note that there are some explanatory texts on larger screens.

plurals
  1. POUnderstanding how reference variables work
    primarykey
    data
    text
    <blockquote> <p>Okay, I'm stymied on how to pull a value out of a void type to bring it back to main using a reference variable. I've read the section in my textbook several times but the code snips it gives don't make sense to me and there aren't very many of them. Could someone possibly explain, or give a simple code example?</p> <p>Thanks</p> </blockquote> <p>Here is the code I have, what is supposed to happen is I'm supposed to pull 5 test scores from the user using the first function called by my main. The next function called by main is supposed to call a third function which determines the lowest of the test scores and removes it from the middle function's calculations.</p> <p>I tried running the code (using just text stubs and the variables without calculations) but my variables all show up as that huge number that is the maximum they can be, not the user input they're SUPPOSED to show up as.</p> <pre><code>#include &lt;iostream&gt; #include &lt;cmath&gt; #include &lt;string&gt; using namespace std; int main() { double score1, score2, score3, score4, score5, average; void getScore(double &amp;); void calcAverage(double &amp;); int findLowest(); getScore(score1); getScore(score2); getScore(score3); getScore(score4); getScore(score5); calcAverage(average); cout&lt;&lt;"Let's see what we have here.\n" &lt;&lt;score1&lt;&lt;endl&lt;&lt;score2&lt;&lt;endl&lt;&lt;score3&lt;&lt;endl&lt;&lt;score4&lt;&lt;endl&lt;&lt;score5&lt;&lt;endl&lt;&lt;average; system("pause"); return 0; } void getScore(double &amp;) { double score; cout&lt;&lt;"Please enter a test score."; cin&gt;&gt;score; while(score&lt;0 || score&gt;100) { cout&lt;&lt;"Please enter a valid score."; cin&gt;&gt;score; } } void calcAverage(double &amp;) { int findLowest(); double lowest; cout&lt;&lt;"Yes, I'm a stub."; lowest = findLowest(); } int findLowest() { cout&lt;&lt;"I'm a stub too!"; return 5; } </code></pre>
    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