Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 928033
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T19:56:41+00:00 2026-05-15T19:56:41+00:00

Possible Duplicate: C++ passing variables in from one Function to the Next. The Program

  • 0

Possible Duplicate:
C++ passing variables in from one Function to the Next.

The Program is working but when it comes to getUserData it asks for the same information 4 times and then displays the results with negative numbers. I used test numbers for number of rooms 1, 110 for sqrt feet in the room, 15.00 for cost of paint.

 //Problems with this not working
   void showMenu();
void getUserData(int &, double &, int &);
void doEstimate(int &, double &, int &, double &, double &);
void showReport();

    int main()
{
 int choice;
//I am not sure why I have to do this but someone suggested to do it and the program complied when I did this int calc ect

int calcGallonsOfPaint, rooms, totalsqrtfeet;
 double calcCostOfPaint, costOfPaint;
 int calcHoursOfLabor;
 double calcLaborCost;
 double calcPaintJobCost;

   // 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)
      {
    //for some reason it just keeps repeating the function getUserData
 getUserData(rooms, costOfPaint, totalsqrtfeet);
 doEstimate(calcGallonsOfPaint, calcCostOfPaint, calcHoursOfLabor, calcLaborCost, calcPaintJobCost);
 showReport();


    }
   } while (choice != 2);
   return 0;
}


    void getUserData(int &rooms, double &costOfPaint, int &totalsqrtfeet)
{
 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 each room: ";
 cin >> sqrtfeet;

 for (count = 1; 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;

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

void doEstimate(int &calcGallonsOfPaint, double &calcCostOfPaint, int &calcHoursOfLabor, double &calcLaborCost, double &calcPaintJobCost)
{
//I am not sure why I have to do this but someone suggested to do it and the program complied when I did this: puting int rooms ect 
int rooms, totalsqrtfeet;
 double costOfPaint;

 getUserData(rooms, costOfPaint, totalsqrtfeet);

 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;  

/*110 square feet of wall space
one gallon of paint
six hours of labor
$15.00 per hour for labor
*/

}

void showReport()
{

//I am not sure why I have to do this but someone suggested to do it and the program complied when I did this 
int calcGallonsOfPaint, rooms, totalsqrtfeet;
 double calcCostOfPaint, costOfPaint;
 int calcHoursOfLabor;
 double calcLaborCost;
 double calcPaintJobCost;

 getUserData(rooms, costOfPaint, totalsqrtfeet);
 doEstimate(calcGallonsOfPaint, calcCostOfPaint, calcHoursOfLabor, calcLaborCost, 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");
}
  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T19:56:42+00:00Added an answer on May 15, 2026 at 7:56 pm

    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 🙂

    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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 530k
  • Answers 530k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Try this rule: RewriteRule ^pics/\d{2}/([^/]+/[^/]+/[^/]+)$ pics/$1 Edit     Since you’re using… May 16, 2026 at 11:40 pm
  • Editorial Team
    Editorial Team added an answer One thing I read is that there's a known bug… May 16, 2026 at 11:40 pm
  • Editorial Team
    Editorial Team added an answer You are using field access strategy (determined by @Id annotation).… May 16, 2026 at 11:40 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

Possible Duplicate: Passing varible types though mod-rewrite howdy, I'm using the get method on
Possible Duplicate: C#: Passing null to overloaded method - which method is called? Here
Possible Duplicate: Default value to a parameter while passing by reference in C++ Is
Possible Duplicate: In PHP (>= 5.0), is passing by reference faster? I wonder if
Possible Duplicate: How can I pre-set arguments in JavaScript function call? (Partial Function Application)
Possible Duplicate: Difference between Convert.tostring() and .tostring() Hi Carrying on from this question What
Possible Duplicate: Is Java pass-by-reference? I found an unusual Java method today: private void
Possible Duplicate: Why do I get a segmentation fault when writing to a string?
Possible Duplicate: Should I learn C before learning C++? As a professional (Java) programmer
Possible Duplicate: How do you give a C# Auto-Property a default value? Hi all:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.