The big picture is to take information from one file to another file. I've done that and it works well. The next thing I need to do is find the highest value from the new file. The basic format is like this: I have a bunch of "workers", I have the days they have worked, the hours & minutes they've worked. In the new file I have it formatted to show the pay rate (I enter the value as a cin) and then I have the total amount of money they made (everyone makes the same amount.. that which is in the cin). For some reason, I cannot make a function (that works) that will extract the persons name that makes the most money, and how much money that is. I got a little frustrated and was trying whatever I could so the new function is sloppy and ridiculous, but I was hoping you could help. To keep this a general question and not a specific question, I was wondering if you guys could just explain how to do something like this (finding the highest value & outputting it WITH the name of the person.. so essentially a double for the money and a string with the persons name) using parts of my code as an example:
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
#include <cstdlib>
using namespace std;
void getandprintaddress (ifstream&, ofstream&); // this function will be used to get the data from one file and input it into the next with the total amount of money made from each person as well as the next function
double highestpaid(double& highesttotal, double& totalpay, string highestpaidemp, string name); // this function is what will be used to find the highest amount of money and the person who has it
void name(); // This is to input my name in the file.
struct employees // This is the structure with all of the information that will be used to calculate everything.
{
string name; // person's name
string highestpaidemp; // highest paid employee
string address; // the address of the employee
string address2;
int days; // days worked
int hours; //hours worked
double minutes; // minutes worked
int total_hours; // total hours worked
double totalpay; // total pay
double payrate; // pay rate
double total_minutes; // minutes worked
double total_time; // total hours and minutes worked
double highesttotal; // the highest total amount of money made between all employees.
};
int main(){
ifstream inputFile;
ofstream outputFile;
getandprintaddress(inputFile, outputFile);
return 0;
}
void getandprintaddress(ifstream& inputFile, ofstream& outputFile) // the main function that will be used to get and output all the information.
{
struct employees();
ifstream getdata;
ofstream outdata;
int employees_t;
employees employeeinfo;
string inputfile;
string outputfile;
cout << "What is the name of your input file? "<<endl; // this will be the file you open
cin>>inputfile;
getdata.open(inputfile.c_str());
if(getdata.fail()){ // this is meant to be used if someone enters a file that isn't there
cout << "The input file has failed to open. \n";
exit(1);
}
cout << "What is the name of your output file? \n"; // what you want the title of the new file to be.
cin>>outputfile;
outdata.open(outputfile.c_str());
if(outdata.fail())
{
//This is if the new file is invalid
cout << "The outputfile failed to open. \n";
exit(1);
}
cout << "How many employees are there? \n" ;
cin >> employees_t; // Enter how many employees there are
cout << "What is the employees hourly payrate? \n";
cin >> employeeinfo.payrate; // how much each employee makes.
for ( int info = 0; info < employees_t; info++)
{
employeeinfo.highesttotal = 0.0; // this will be needed for calculating the highest paid employee
employeeinfo.total_minutes = 0.0; // This is needed to calculate total minutes
employeeinfo.total_hours = 0; // Same as the total_minutes, but for hours instead.
employeeinfo.total_time = 0.0; // Needed to calculate total time
string line1;
getline(getdata, employeeinfo.name);
outdata << "Name: " << employeeinfo.name <<endl; // employees name
getline(getdata, employeeinfo.address);
outdata << "Address: \n"; // Employees address
outdata<< employeeinfo.address <<endl;
getline(getdata, employeeinfo.address2);
outdata <<employeeinfo.address2 <<endl;
getdata >> employeeinfo.days;
outdata << "Days worked: " <<employeeinfo.days << endl; // Days worked
for (int totalworked=0; totalworked<employeeinfo.days; totalworked++)
{
// Because the employees work different amount of days, this loop is needed to post the individual information from each employee
getdata >> employeeinfo.hours >> employeeinfo.minutes;
employeeinfo.minutes = employeeinfo.minutes / 60;
employeeinfo.total_hours = employeeinfo.total_hours + employeeinfo.hours;
employeeinfo.total_minutes = employeeinfo.total_minutes + employeeinfo.minutes;
employeeinfo.total_time = employeeinfo.total_minutes + employeeinfo.total_hours;
employeeinfo.totalpay = employeeinfo.total_time * employeeinfo.payrate;
outdata << employeeinfo.hours <<" hours "<< employeeinfo.minutes*60 << " minutes"<< endl;
}
outdata << fixed << showpoint << setprecision(1); // Setting the total hours worked to 1 decimal so that to include the minutes
outdata << "Total hours worked: "<<employeeinfo.total_time<<endl; // Total hours worked
outdata << fixed << showpoint << setprecision(2); // Setting the decimal to two places
outdata << "Hourly pay: $"<<employeeinfo.payrate << endl; //Hourly pay
outdata << "Gross pay: $" <<employeeinfo.totalpay <<endl; // Gross pay
getline(getdata,line1);
getline(getdata,line1);
outdata << "\n";
double highestpaid(employeeinfo.highesttotal, employeeinfo.totalpay);
}
};
double highestpaid(double& highesttotal, double&totalpay, string highestpaidemp, string name)
{
if (highesttotal < totalpay)
{
highesttotal = totalpay;
highestpaidemp = name;
}
return highestpaid(double& highesttotal, double&totalpay, string highestpaidemp, string name);
};
Ok, I'm going to answer your general question rather than spend too long searching through your code, but hopefully should work for both.
You have your struct employee
Stick them all in a vector of employees (which i'll call workers)
vector<struct employee> workers
using a vector means you can just keep on adding more to the end, but an array would work too if you had a fixed number of workers
now each worker can be identified by an integer index, 0 to n-1, where n is number of workers. Now can just iterate through (quicker methods if very large number of workers but probably fine here) to find highest salary
double highestPay = 0;
int highestPaidIndex = 0;
for(int i = 0; i++; i < n)
{
if(workers[i].totalpay > highestPay)
{
highestPay = workers[i].totalpay;
highestPaidIndex = i;
}
}
Now highestPaidIndex is the index of the highest paid employee, who has name workers[highestPaidIndex].name and total earnings workers[highestPaidIndex].totalpay
Hope that solves both your general and specific question
Related
I have coded a program in C++ for an assignment in my C++ Intro class but I have multiple errors in the program but I can't seem to figure out how to get all of the bugs out.
The program is supposed to ask the user for the name of the movie, the number of adult and child tickets sold, and calculate the gross box office profit, net box office profit and the amount paid to the distributor.
I can't seem to figure out how to initialize the variables adultTicketPrice and
childTicketPrice and I thought I declared them and am trying to figure out if they need to get initialized if I already declared them?
And how is the childTicket price out of scope?
And why am I getting the other errors and how can I fix them?
// Michael VanZant
// Flix for Fun Profit Report
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
int main()
{
// Create all double variables
double adultTicketsSold, childTicketsSold, grossBoxProfit, netBoxProfit,
amtPaidDist, adultTicketPrice, childTicketPrice
adultTicketPrice = 12;
childTicketPrice = 7;
cout << fixed << setprecision(2);
// Create the string variable
string movieName;
// Get the name of the movie and store it in the movieName string
cout << "What is the name of the movie?";
getline(cin, movieName);
cout << "\n";
// Cin.ignore to ignore the string variable type
cin.ignore();
// Get the amount of adult and child tickets sold
cout << "How many adult tickets do you want to buy?";
cin >> adultTicketsSold;
cout << "\n";
cout >> "How many child tickets did you want to buy?";
cin >> childTicketsSold;
cout << "\n";
// Calculate the amount of gross box office profit and display it
grossBoxProfit = (childTicketsSold * childTicketPrice) + (adultTicketsSold * adultTicketPrice);
cout << "Gross Box Office Profit: $" << grossBoxProfit;
cout << "\n";
// Calculate the net box profit amount and display it
netBoxProfit = grossBoxProfit * .20;
cout << "Net Box Profit Amount: $" << netBoxProfit;
cout << "\n";
// Calculate the amount paid to distributor and display it
amtPaidDist = grossBoxProfit - netBoxProfit;
cout << "Amount Paid to Distributor is: $" << amtPaidDist;
return 0;
}
When the compiler says "expected initialiser", it has nothing to do with these lines:
adultTicketPrice = 12;
childTicketPrice = 7;
which are actually assignments, not initialisations (though some old C terminology would call the first assignment an initialisation).
No, it's because it thinks you're still on this line, providing declarations and (optionally) initialisers:
double adultTicketsSold, childTicketsSold, grossBoxProfit, netBoxProfit,
amtPaidDist, adultTicketPrice, childTicketPrice
That's because you didn't put a ; at the end of it.
Also:
cout >> "How many child tickets did you want to buy?";
You meant <<.
Fixing those two little typos, the code compiles.
I am fairly new to this site, and programming in not my strong suit, so I apologize if the way I word things are hard to follow. Below is a code I have written to calculate the odds of profiting from playing lottery scratchers. It is suppose to output the results to a .txt file. I am able to get it to output to that file, and the everything in the output file is correct, except for the name of the second game. It is missing a whole word. How my output file looks is shown below.
Game Cost Odds
-----------------------------------------------
SMALL BEANS $ 1 1 in 1.67
BOOTY, ARRR $ 10 Not possible
MONEY HU$TLA$ $ 20 1 in 99.80
The second and third games both have a space before they start, and I am not sure why. Also, the second game is suppose to say "Pirate's Booty, Arrr." I do not understand how a whole word is missing. Any help on how to fix this would be very much appreciated. My code is below.
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
using namespace std;
int main()
{
// Declaring Variables
int Profit; // The lowest dollar amount you want to profit
int CostOfTicket; // The cost of the ticket in the dollar amount
int NumberOfPrizes; // The number of possible prizes that can be won
int PrizeValue; // The value of the prize in dollars
int NumberOfTickets; // The total number of tickets that were printed with that prize
int TicketsNotClaimed; // The number of tickets with that prize that have not yet been claimed
double RemainingTickets; // Total number of tickets that are remaining
double RemainingTicketsForProfit; // The total number of tickets for a profit that are remaining
double Odds; // The odds of winning the game
string game; // The name of each game that can be played
string output; // The name of output file the user chooses (.txt)
// Open the input text file
ifstream inputfile ("scratcher.txt"); // Open the input file called "scratcher.txt"
// The program will ask the user to enter the lowest amount they would like to profit by when playing one of the lottery games.
// The games include "Small Beans," "Pirate's Booty, Arrr," and "Big Money Hu$tla$."
cout << "Enter the lowest dollar amount that you would like to profit: ";
cin >> Profit;
cout << "Enter the output file name: ";
cin >> output; //name of output file user chooses
ofstream outputfile (output.c_str()); //creates an output file with the name user chose for output
cout << "Generating report...";
// How the output will be formatted
outputfile << left << setw(25) << "Game" << setw(10) << "Cost" << setw (10) << "Odds" << endl;
outputfile << "-----------------------------------------------" << endl;
// Reads the name of the game
while (getline(inputfile, game))
{
inputfile >> CostOfTicket; // Reads the cost of the ticket
inputfile >> NumberOfPrizes; // Reads the number of prizes
RemainingTickets = 0;
RemainingTicketsForProfit = 0;
for (int i = 0; i < NumberOfPrizes; i++)
{
inputfile >> PrizeValue; // Reads the value of the prize
inputfile >> NumberOfTickets; // Reads the total number of tickets
inputfile >> TicketsNotClaimed; // Reads the number of tickets that are not claimed
RemainingTicketsForProfit = RemainingTicketsForProfit + TicketsNotClaimed;
// The next line will compute a sum of the number of the remaining tickets where the user would profit
if (PrizeValue > Profit)
{
// The following line computes the running sum of the number of tickets remaining for that game.
RemainingTickets = RemainingTickets + TicketsNotClaimed;
}
}
// Tells the program what to do if there are no tickets remaining
if (RemainingTickets == 0)
{
// Formats the output
outputfile << left << setw(25) << game << setw (2) << "$" << CostOfTicket << right << setw(15) << "Not possible" << endl;
}
else
{
// Tells the program to calculate the odds.
Odds = RemainingTicketsForProfit / RemainingTickets;
outputfile << left << setw(25) << game << setw (2) << "$" << CostOfTicket << right << setw(15) << "1 in " << setprecision(2) << fixed << Odds << endl;
}
string blankLine;
inputfile >> blankLine;
}
// Closes the input and output text file
inputfile.close();
outputfile.close();
return 0;
}
string blankLine;
inputfile >> blankLine;
Not sure why you did this but it's eating up the first word of your next line.
Remember, operator>> into a string skips whitespace then eats precisely one word.
Whatever you're trying to do regarding skipping blank lines, this is not how to do it!
I am trying to create a program that ask for sales amount and displays total salary and writes the entry to a file. However my program has is only writing the last entry to the file. I have searched online for 2hours for a solution and cant find one.
I want all of the input to write to my file not just the last one
#include <fstream>
#include <iostream>
#include <iomanip>
using namespace std;
void SavingFile(); //Declartion
void Calculate();
char FileName[20];
double GrossPay;
double TotalSalary;
int employeeID=0;
char response;
int i=1;
int main()
{
SavingFile();
}
void SavingFile()
{
cout << "\nEnter the name of the file you want to create: ";
cin >> FileName;
do
{
employeeID++;
cout << endl << endl << "Enter sales amount for sales person ID " << employeeID <<" : $";
cin >> GrossPay;
Calculate();
cout <<"Sales amount for ID " << employeeID <<" : $" << TotalSalary <<endl;
cout <<endl <<endl;
do
{
ofstream Employee(FileName);
Employee <<"Employee ID: "<< employeeID <<" Sales Amount: $" << TotalSalary <<endl;
cout << endl;
i++;
}
while
(employeeID == i);
cout << "Do you want to process another employee ? (y/n): ";
cin >> response;
}
while ( (response == 'Y') || (response == 'y') );
}
void Calculate() // definition
{
TotalSalary = (GrossPay * .10) + 150;
//return TotalSalary;
}
You are overwriting the file every time you write to it.
If you want to append to the file, you need to open the file using the ios_base::app flag in addition to ios_base::out.
In your code, you must replace this:
ofstream Employee(FileName);
with this:
ofstream Employee(FileName, ios_base::out | ios_base::app);
To learn more, you can read this page on the constructor of the ofstream class. Among other things, you will find a description of the various flags you can use and what they mean.
I won't rewrite your code for you, but I'll explain the logic that you need to rewrite.
In a loop, you read a value, and call Calculate, which sets a global variable called TotalSalary. The cout probably looks ok. Try adding a cout into the while loop where you are outputting the file, and you'll see that the values aren't what they used to be.
The problem is that every time you call Calculate, you overwrite TotalSalary. You're not saving these values anywhere, but by looping through, you're assuming that the values are still there.
The solution is to write to the output file at the same time as you write to your cout. Open the ofstream at the top of main, and just output to there like you are outputting to cout.
There's no need to open the file each time in a loop, and in fact you shouldn't. (Though appending would help, if that's what you should have been doing.)
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
Everything else in my program is running correctly i just need help to set up a void function to calculate the highest paid customer.
/* Hector Gutierrez
Date: November 27,2013
Math 1900
This program reads information from a file and displays it to an output file alone with there pay rate for the number of days they work
*/
# include <iostream>
# include <fstream>
# include <string>
# include <cstdlib>
# include<iomanip>
using namespace std;
struct Client_Bill_Info
{
string name;
string adress1;
string adress2;
int numjobs;
double hours;
double min;
double totaltime;
double totalmin;
double total;
double totalhours;
double paycheck;
};
void name(ofstream&);
void getandprintadress ( ifstream& ,ofstream&,int,double);
void openfiles( ifstream& , ofstream&, string,string);
void highlypaid(ifstream&,ofstream&,int,double );
int main()
{
ifstream getdata;
ofstream outdata;
int jobs;
double payrate;
string inputfile;
string outputfile;
openfiles( getdata,outdata,inputfile,outputfile);
name (outdata);
cout<<"How many Jobs "<<endl;
cin>>jobs;
cout<<"How much does the company charge per Hour: "<<endl;
cin>>payrate;// how much you pay
Client_Bill_Info customers;
getandprintadress (getdata,outdata,jobs,payrate);
return 0;
}
I'm not sure if I'm calling my void function correctly in my Main program
This is the void function that I'm trying to create to output the highest paid customer. I know I have to create an if statement but I don't know how to set that up.
void highlypaid (ifstream getdata,ofstream outdata,int jobs,double payrate)
{
}
This should be a void function that reads data from a file and outputs it to another, outputting name, address, number of jobs worked, hours they worked and how much they made.
void getandprintadress (ifstream& getdata, ofstream& outdata, int jobs,double payrate)
{
for (int m =0; m<jobs; m++)// By having cin>>employee here it allow for it to loop as many as number of employess you have
{
Client_Bill_Info customers;//this allows the structure to be included in the function
customers.totalhours = 0;// All these variables must be set equal to zero in order to repeat sum of the valuse by reseting it back to zero
customers.totalmin = 0;
customers.totaltime= 0;
//initially set employee.totalhours,totalmin,totaltime to 0
getline(getdata, customers.name);// gets the first line of data which is the name
getline(getdata, customers.adress1);// Second line of data that reads the adresss
getline(getdata, customers.adress2);// third line of datat that reads the second part of adress
//get the Employee's days worked.
getdata>> customers.numjobs;
outdata << "Customer Information "<<"\n";
outdata << customers.name << "\n";
outdata << customers.adress1 << "\n";
outdata << customers.adress2 << "\n";
outdata << "Number of jobs: " << customers.numjobs << "\n";
for(int i=0; i<customers.numjobs;i++)// loops the program how many days work then reads the number of minutes worked below.
{
getdata>>customers.hours>>customers.min;//gets the hours and minutes displayed like this because it has to read the hours and minute in a single line
customers.min = customers.min/60;//converts minutes to hours for instance 30 min is .5 hours
customers.totalmin += customers.min;// after being converted from min to hours it takes the sum of minutes
customers.totalhours += customers.hours;// taking the sum of the hours
customers.totaltime = customers.totalmin + customers.totalhours;//adds the total minutes and time to calculate wage
outdata<<"Job: "<< i+1 <<": "<<customers.hours<<" Hours "<<" and "<<customers.min*60<<" "<<" minutes "<<endl;
string dummy;
getline(getdata,dummy);
}//calculate the employee's pay check amount
customers.paycheck = (customers.totaltime * payrate);
// outputs data to my outputfile
outdata << fixed << showpoint << setprecision(2);
outdata << "Amount of Bill: $ " << customers.paycheck << "\n\n";
//Display the employee data to output file.
getdata.ignore();//get the new line
getdata.ignore();
}
return;
}
void openfiles( ifstream& getdata , ofstream& outdata, string inputfile,string outputfile )
{
cout<<"what is the name of your inputfile"<<endl;
cin>>inputfile;
getdata.open(inputfile.c_str());
if (getdata.fail())//test file as true
{
cout<<"Opening File Failed "<<endl;
exit(1);
}
cout<<" What is the name of your output file"<<endl;
cin>>outputfile;
outdata .open(outputfile.c_str());
if (outdata.fail())//test file if true
{
cout<<" File has Fail"<<endl;
exit(1);
}
return;
}
void name(ofstream& outdata)
{
outdata<<"Hector Gutierrez"<<endl;
outdata<<"This program Will Read data from a file and output it to another."<<endl;
outdata<<"Also this program specifically calculates the number of jobs one has work and"<<endl;
outdata<<"how many total hours the company has work at the customers lawn."<<endl;
outdata<<"This program will also calculate the highest payed customer he/she per week"<<endl;
outdata<<endl;
outdata<<endl;
outdata<<endl;
return;
}
This is my output file
Customer Information
Gavin K. Smith
3928 Ottis Street
Cleveland TN 37311
Number of jobs: 5
Job: 1: 1 Hours and 34 minutes
Job: 2: 2 Hours and 45 minutes
Job: 3: 1 Hours and 55 minutes
Job: 4: 2 Hours and 45 minutes
Job: 5: 0 Hours and 30 minutes
Amount of Bill: $ 85.35
... repeat for other customers....
This is what i trying to output:
The highest paid customer is Name the amount paid per week is Amount
Declare a variable.
Initialize it to the first value.
Loop through all the values (you can skip the first one if you like). If that value is greater than the value in the variable, set the variable to that value.
You now have the highest value in that variable and can do whatever you like with it.
This question already has answers here:
Closed 12 years ago.
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");
}
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.
To caveat on what paxdiablo said, you are calling getUserData in your nested while loop, but I don't understand the purpose of calling getUserData(rooms, costOfPaint, totalsqrtfeet); prior to doEstimate(...) when the data isn't used nor passed to doEstimate(...) until you call getUserData again while inside the doEstimate(...) function. You should pass by value the rooms, costOfPaint, and totalsqrtfeet variables to doEstimate(...) or make them global since you only have one main() function anyways. If you had some sort of OO solution, then I wouldn't recommend making them global and rather part of a class.
Also all these variables are ZERO or NULL when they are passed into doEstimate(...):
calcGallonsOfPaint, calcCostOfPaint, calcHoursOfLabor, calcLaborCost, calcPaintJobCost
If you want to output them, then you need to pass them by reference to doEstimate(...) and then when it gets to the cout then it will sufficiently print the correct values. That is why it is zero.
The bottom line is though you need one function to call the other functions. That would be the simplest plan at this point, such as:
GetDataAndPrint(...) {
// Get some data
// Do estimate, pass in values by reference
// Print Results from calculated values
// return
}