Пожалуйста, Решите / Ответьте C ++ Программные проблемы с Функциональными Переменными

Пожалуйста, решите / ответьте на проблемы, чтобы заставить программу работать. Я не совсем понимаю передаваемые переменные по ссылке или значению, и я думаю, что это делает это так сложно. Так что, если вы могли бы исправить программу. Я был в этом в течение последних 2 дней. Я включил свой полный код.

Паксдиабло предложил это, и я пытаюсь сделать то, что они сказали

«Одна вещь, которую вы должны сделать, это инициализировать totalsqrtfeet в ноль в вашей главной функции. Это потому, что вы просто добавляете к ней размер каждой комнаты, и она начинается со случайного значения: junk + a + b + c + d все еще барахло :-)

Кроме того, вы вызываете getUserData из своей основной функции, а затем снова из doEstimate. А потом вы снова вызываете их в showReport. Вот почему он спрашивает четыре раза. Просто вызовите getUserData один раз. Поскольку это домашнее задание, я оставлю вас выяснить, где, но вот подсказка. Если вы сделаете это в main (nudge, nudge, wink, wink), вам придется также передать переменные в doEstimate, а не создавать новые переменные с тем же именем в этой функции и волшебным образом ожидать, что компилятор свяжет их с оригиналы. "

Когда я ввожу данные испытаний 1 комнаты, 110 кв.м, 15.00. Я получаю правильное число для комнат в функции отчета, но 0 для всего остального

 #include <iostream>
#include <cstdlib>
#include <cmath>
#include <iomanip>

using namespace std;

// Function prototypes
void showMenu();
void getUserData(int &, int &, double &);
void doEstimate(int &, int &, double &, int &, double &, int &, double &, double &);
void showReport(int &, int &, double &, int &, double &, int &, double &, double &);

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 << fixed << showpoint << setprecision(2);

   do
   {
      // Display the menu and get the user's choice.
      showMenu();
      cin >> choice;

      // Validate the menu selection.
      while (choice < 1 || choice > 2)
      {
         cout << "Please enter 1 or 2: ";
         cin >> 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 << "\n\t\tPaint Job Estimator Menu\n\n";
   cout << "1. Get Paint Job Estimate\n";
   cout << "2. Quit the Program\n\n";
   cout << "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 &rooms, int &totalsqrtfeet, double &costOfPaint)
{
    int sqrtfeet;
    int count = 0;

    cout << "Please enter the number of rooms to be painted: ";
    cin >> rooms;

    cout << "Please enter square feet of wall space in room 1: ";
    cin >> sqrtfeet;

    for (count = 2; count <= rooms; count++)
        {   
            cout << "Please eneter square feet of wall space in room " << count << ": ";
            cin >> sqrtfeet;
            totalsqrtfeet += sqrtfeet;
        }   

    cout << "What is the cost of the paint: ";
    cin >> costOfPaint;
}

void doEstimate(int &rooms, int &totalsqrtfeet, double &costOfPaint, int &calcGallonsOfPaint, double &calcCostOfPaint, int &calcHoursOfLabor, double &calcLaborCost, double &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 &rooms, int &totalsqrtfeet, double &costOfPaint, int &calcGallonsOfPaint, double &calcCostOfPaint, int &calcHoursOfLabor, double &calcLaborCost, double &calcPaintJobCost)
{


    cout << "The number of rooms to be painted: " << rooms << endl;
    cout << "The number of whole gallons of paint required: " << calcGallonsOfPaint << endl;
    cout << "The hours of labor required: " << calcHoursOfLabor << endl;
    cout << "The cost of the paint: " << calcCostOfPaint << endl;
    cout << "The labor charges: " << calcLaborCost << endl;
    cout << "The total cost of the paint job: " << calcPaintJobCost << endl;

    system("pause");
    system("cls");
}

Ответы на вопрос(0)

Ваш ответ на вопрос