title: Please Solve/Answer C++ Program problems with Functions Variables
body: <p>Please solve/answer problems to get program to work. I am not fully understanding the passing variables by reference or value and I think that is what is making this so hard. So if you could fix the program. I've been at this for the last 2 days. I have included my full code.</p>
  
  <p>paxdiablo suggested this and I'm trying to do what they said</p>
  
  <p>"One thing that you should do is initialise totalsqrtfeet  to zero in your main function. That's because you're just adding the size of each room to it and it starts out with a random value: junk + a + b + c + d is still junk :-)</p>
  
  <p>On top of that, you call getUserData from your main function and then again from doEstimate. And then you call them both again in showReport. That's why it's asking four times. Just call getUserData once. Since it's homework, I'll leave you to figure out where but here's a hint. If you do it in main (nudge, nudge, wink, wink), you'll have to pass he variables into doEstimate as well, not create new variables of the same name within that function and magically expect the compiler to associate them with the originals.
  "</p>
  
  <p>When I enter test data of 1 room, 110 sqrt feet, 15.00. I get the right number for rooms in the report function but 0 for everything else</p>
  
  <pre><code> #include &lt;iostream&gt;
  #include &lt;cstdlib&gt;
  #include &lt;cmath&gt;
  #include &lt;iomanip&gt;
  
  using namespace std;
  
  // Function prototypes
  void showMenu();
  void getUserData(int &amp;, int &amp;, double &amp;);
  void doEstimate(int &amp;, int &amp;, double &amp;, int &amp;, double &amp;, int &amp;, double &amp;, double &amp;);
  void showReport(int &amp;, int &amp;, double &amp;, int &amp;, double &amp;, int &amp;, double &amp;, double &amp;);
  
  int main()
  {
      int choice = 0;
      int calcGallonsOfPaint = 0, rooms = 0, totalsqrtfeet = 0;
      double calcCostOfPaint = 0, costOfPaint = 0;
      int calcHoursOfLabor = 0;
      double calcLaborCost = 0;
      double calcPaintJobCost = 0;
  
     // Set up numeric output formatting.
     cout &lt;&lt; fixed &lt;&lt; showpoint &lt;&lt; setprecision(2);
  
     do
     {
        // Display the menu and get the user's choice.
        showMenu();
        cin &gt;&gt; choice;
  
        // Validate the menu selection.
        while (choice &lt; 1 || choice &gt; 2)
        {
           cout &lt;&lt; "Please enter 1 or 2: ";
           cin &gt;&gt; choice;
        }
  
        if (choice == 1)
        {
  
          //User enters information
          getUserData(rooms, totalsqrtfeet, costOfPaint);
  
          //Information from getUserData is used to make calculations
          doEstimate(rooms, totalsqrtfeet, costOfPaint, calcGallonsOfPaint, calcCostOfPaint, calcHoursOfLabor, calcLaborCost, calcPaintJobCost);
  
          //Report is generated from user input and calculations
          showReport(rooms, totalsqrtfeet, costOfPaint, calcGallonsOfPaint, calcCostOfPaint, calcHoursOfLabor, calcLaborCost, calcPaintJobCost);
  
         }
     } while (choice != 2);
     return 0;
  }
  
  //*****************************************************************
  // Definition of function showMenu which displays the menu.       *
  //*****************************************************************
  
  void showMenu()
  {
     cout &lt;&lt; "\n\t\tPaint Job Estimator Menu\n\n";
     cout &lt;&lt; "1. Get Paint Job Estimate\n";
     cout &lt;&lt; "2. Quit the Program\n\n";
     cout &lt;&lt; "Enter your choice: ";
  }
  
  /*
  After the paint job estimate is displayed, the menu should be displayed again. 
  The number of rooms must be at least 1, the price of the paint per gallon must be at least $15.00, 
  and the area for the wall space of each room must be greater than 10 square feet. 
  All input validation must be performed with a loop.
  */
  
  void getUserData(int &amp;rooms, int &amp;totalsqrtfeet, double &amp;costOfPaint)
  {
      int sqrtfeet;
      int count = 0;
  
      cout &lt;&lt; "Please enter the number of rooms to be painted: ";
      cin &gt;&gt; rooms;
  
      cout &lt;&lt; "Please enter square feet of wall space in room 1: ";
      cin &gt;&gt; sqrtfeet;
  
      for (count = 2; count &lt;= rooms; count++)
          {   
              cout &lt;&lt; "Please eneter square feet of wall space in room " &lt;&lt; count &lt;&lt; ": ";
              cin &gt;&gt; sqrtfeet;
              totalsqrtfeet += sqrtfeet;
          }   
  
      cout &lt;&lt; "What is the cost of the paint: ";
      cin &gt;&gt; costOfPaint;
  }
  
  void doEstimate(int &amp;rooms, int &amp;totalsqrtfeet, double &amp;costOfPaint, int &amp;calcGallonsOfPaint, double &amp;calcCostOfPaint, int &amp;calcHoursOfLabor, double &amp;calcLaborCost, double &amp;calcPaintJobCost)
  {
  
  
      calcGallonsOfPaint = 1 * (totalsqrtfeet/110);           //Calculates the number of whole gallons of paint required.
  
      calcCostOfPaint = calcGallonsOfPaint  * costOfPaint;    //Calculates the cost of the paint required.
  
      calcHoursOfLabor = calcGallonsOfPaint * 6;              //Calculates the number of whole hours of labor required.
  
      calcLaborCost = calcHoursOfLabor * 15.00;               //Calculates the labor charges.
  
      //Calculates the cost of the paint job. This is the sum of the labor charges and the cost of the paint required.
      calcPaintJobCost = calcLaborCost + calcCostOfPaint;     
  
  
  }
  
  void showReport(int &amp;rooms, int &amp;totalsqrtfeet, double &amp;costOfPaint, int &amp;calcGallonsOfPaint, double &amp;calcCostOfPaint, int &amp;calcHoursOfLabor, double &amp;calcLaborCost, double &amp;calcPaintJobCost)
  {
  
  
      cout &lt;&lt; "The number of rooms to be painted: " &lt;&lt; rooms &lt;&lt; endl;
      cout &lt;&lt; "The number of whole gallons of paint required: " &lt;&lt; calcGallonsOfPaint &lt;&lt; endl;
      cout &lt;&lt; "The hours of labor required: " &lt;&lt; calcHoursOfLabor &lt;&lt; endl;
      cout &lt;&lt; "The cost of the paint: " &lt;&lt; calcCostOfPaint &lt;&lt; endl;
      cout &lt;&lt; "The labor charges: " &lt;&lt; calcLaborCost &lt;&lt; endl;
      cout &lt;&lt; "The total cost of the paint job: " &lt;&lt; calcPaintJobCost &lt;&lt; endl;
  
      system("pause");
      system("cls");
  }
  </code></pre>