uninitialized?, tuitionCost, local Variable, [closed] - c++

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 6 years ago.
Improve this question
int main()
{
double tuitionCalc(int sumCreditHoursTaken);
int numCourses;
double total = 0.0;
double tuitionCost= 0.0;
cout << "\t\t This Program calculates a student's total number of\n";
cout << "\t\tcredit hours and tution for a given semester.\n";
cout << "\nPlease enter the number of Courses you will be taking this semester: ";
cin >> numCourses;
for ( int count = 1; count <= numCourses; count++)
{
double sumCreditHoursTaken;
cout << " please enter the number of credit hours for course" << count << ": ";
cin >> sumCreditHoursTaken;
total += sumCreditHoursTaken;
}
cout << fixed << showpoint << setprecision(2);
cout << "Your Total number of credit hours is: " << total << endl;
cout << "Your total tuition will be: $" << tuitionCalc(tuitionCost) << "\n\n";
return 0;
}
and the function im calling is
double tuitionCalc(int sumCreditHoursTaken)
{
double tuitionCost = 0.0;
double costCreditHour = 147.00;
double maxHoursFullTuition = 12;
double maintFeeAddOn = 29.33;`
if (sumCreditHoursTaken <= maxHoursFullTuition)
cout<< " " << (sumCreditHoursTaken * costCreditHour);
else if (sumCreditHoursTaken > maxHoursFullTuition)
cout << " " << (maxHoursFullTuition * costCreditHour) + ((sumCreditHoursTaken - maxHoursFullTuition) * maintFeeAddOn);
return tuitionCost;
}
input for number of courses is 5
and credit hours is 3,3,3.5,4,2.5
i get the total credit hours but icant seem to display the tuition cost?
thank you s

You are never actually assigning a value to tuitionCost in tuitionCalc() method, so it will always be 0.0.
To elaborate: You are returning tuitionCost from tuitionCalc(). You first initialize tuitionCost = 0.0, but never proceed to assign any calculated value to it. Thus, when you return tuitionCost, it will return the value you initialized it to: 0.0.

I haven't examined your code in detail, but if you inputs contain floating point numbers then change the type for sumCreditHoursTaken from int to double.
Also, change the parameter for the invocation of tuitionCalc from tuitionCost to total.

It seems that OP has fallen afoul of misunderstanding scope and how variables are passed to functions.
In main, OP defines tuitionCost. tuitionCalc defines another tuitionCost. These are different tuitionCosts. They represent different locations in memory and can store different values.
Next, because the tuitionCalc function is defined
double tuitionCalc(int sumCreditHoursTaken)
tuitionCalc(tuitionCost) will take tuitionCost convert it to an integer, and pass a copy into tuitionCalc where it will be used with the name sumCreditHoursTaken. One could say OP has three tuitionCalcs at this point. Not what they want.
Breaking down the tuitionCalc prototype, we see that it takes sumCreditHoursTaken, an integer and based on the name the number of credit hours taken, not a total cost. tuitionCalc also returns a double and inferring the purpose of the function from it;'s name, one would expect that it calculates and returns the tuition.
Like Anatoly states in his answer, the input to tuitionCalc should almost certainly be total, the total number of credit hours computed, and the output should be tuitionCost.
Since this has the smell of a homework assignment, it's not in the OP's best interests to fully answer the question. Instead here are a few recommendations:
Eliminate tuitionCost from main. It only serves to increase confusion. You can reuse variable names, but only do it where there is a clear benefit. If you have a cost and a function that takes and uses cost, then using cost for both makes sense. Just remember that cost inside the function is a different entity unless you pass by reference. In
void function(int & cost)
called with
function(cost);
both costs are the same. But in
void function(int cost)
called with
function(cost);
both function's cost is a copy of the caller's cost and any changes made by function will only effect the copy.
Declare variables close to where you use them. This way people reading your code don't have to scroll up and down and otherwise go hunting. It also helps you because it makes mistakes like, "Why am a calling a function that takes an int with a double?" more obvious.
Do not cout in tuitionCalc. Compute and return tuitionCost. Allow main to output tuitionCost. A function with a name like calc should only calculate. Names should describe function as closely as possible.

First of all you should create the function prototype before declaring it.
And there were some confusions in the code you have used I tried my best to omit error hope this is helpful!
#include <iostream>
#include <iomanip>
using namespace std;
double tuitionCal(double sumCreditHoursTaken);
int main() {
double tuitionCalc(int sumCreditHoursTaken);
int numCourses;
double total = 0.0;
//double tuitionCost= 0.0;
cout << "\t\t This Program calculates a student's total number of\n";
cout << "\t\tcredit hours and tution for a given semester.\n";
cout << "\nPlease enter the number of Courses you will be taking this semester: ";
cin >> numCourses;
double sumCreditHoursTaken; // you should create this variable outside the for loop
for ( int count = 1; count <= numCourses; count++)
{
cout << " please enter the number of credit hours for course" << count << ": ";
cin >> sumCreditHoursTaken;
total += sumCreditHoursTaken;
}
double tuitionCost=tuitionCal(total);
cout << fixed << showpoint << setprecision(2);
cout << "Your Total number of credit hours is: " << total << endl;
cout << "Your total tuition will be: $" <<tuitionCost<< "\n\n";// I assume this is what you want
return 0;
}
double tuitionCal(double sumCreditHoursTaken)//the parameter type is double now
{
double tuitionCost = 0.0;
double costCreditHour = 147.00;
double maxHoursFullTuition = 12;
double maintFeeAddOn = 29.33;
if (sumCreditHoursTaken <= maxHoursFullTuition)
tuitionCost=(sumCreditHoursTaken * costCreditHour);
else if (sumCreditHoursTaken > maxHoursFullTuition)
tuitionCost=(maxHoursFullTuition * costCreditHour) + ((sumCreditHoursTaken - maxHoursFullTuition) * maintFeeAddOn);
return tuitionCost;
//I don't see a point of returning the value and couting both you can
//do only one of the oprations
}

Related

writing a code for time to double annual interest rate

I'm trying to write a code for annual interest rate that lets you enter any amount, and it will show you approximately how many years it takes for your money to at least double. The given interest rate is 5% yearly. Thing is, it's not working properly and it's displaying absurdly high numbers, like 200 years or so.
#include <iostream>
using namespace std;
int main() {
int deposit;
int counter;
cout << "Deposit an amount NO LESS than 1000." << endl;
cin >> deposit;
for (deposit ;; deposit = 1.05 * deposit) {
counter = counter+1;
if (deposit >= 2 * deposit) {
cout << endl;
cout << "Your money will double in "<< counter <<" years." << endl;
break;
}
}
}
Instead of using a loop, you could calculate the time taken to double the money directly.
The amount of money is not interesting, so you don't need to store the amount of money. It's only the rate of return that's interesting.
You can calculate it directly as log(2) / log(r) where r is the rate of return. For example log(2) / log(1.05) gives you the exact time to double an initial amount of money with a 5% return.
Include the standard <cmath> header to get std::log().
#include <iostream>
#include <cmath>
int main() {
double yearsToDouble = std::log(2) / std::log(1.05);
std::cout << "Your money will double in "<< yearsToDouble << " years." << std::endl;
}
Use a variable to store the initial deposit so that it can be compared to the cumulative amount with interest.
for (float initdeposit = deposit;; deposit = 1.05 * deposit)
{
counter = counter+1;
if (deposit >= 2 * initdeposit)
{
cout << endl;
cout << "Your money will double in "<< counter <<" years." << endl;
break;
}
}
a.exe
Deposit an amount NO LESS than 1000.
1000
Your money will double in 16 years.
Note: No matter what the amount is, the time taken to double will be the same always. :)
if (deposit >= 2 * deposit) {
cout << endl;
cout << "Your money will double in "<< counter <<" years." << endl;
break;
}
In the above if statement you are expecting deposit to be greater than or equal to 2 times of deposit. Which can only be true in case if the value of deposit is zero or less than zero.
I will suggest you to use a temp variable to keep the input value of deposit and proceed.
To add to the other answers, which are largely correct in pointing out that deposit > 2*deposit can never be true (you need a second variable to record the initial value!), the only reason your loop ends at all is because deposit gets so large that 2*deposit "wraps around" due to overflow.
This appears to make 2*deposit bigger than deposit (logically impossible — you need to fix this comparison!) although strictly speaking the results are undefined.
Apparently this happens to you after 200 or so iterations.
As for suggestions to switch to a floating-point type like double, this is tempting, and may be sufficient in this simple case, but as a general rule you should avoid floating-point when you don't need it as it introduces complexities and inaccuracies for very little gain.
I would recommend counting in integer pennies, or tenths of pennies, instead. You can achieve it by multiplying the input by 100 or 1000. The resulting incremental multiplication by 1.05 will have a rounding factor, then, but this is what the banks will be doing too!
This line
if (deposit >= 2 * deposit) {
Will not evaluate to true (unless deposit is negative or barring someedge case). You probably wanted to compare it to an initial value. So after this:
cin >> deposit;
I would put
double initialDeposit = deposit;
And then change the other line to
if (deposit >= 2 * initialDeposit) {

Why isn't the variables arithmetic working?

Here is code:
#include<iostream>
#include<string>
using std::cout;
using std::cin;
using std::endl;
using std::string;
int score_one;
int score_two;
int score_third;
int final_score = score_one * score_two * score_third;
int main()
{
cout << "What was your first score?" << endl;
cin >> score_one;
cout << "What was your second score?" << endl;
cin >> score_two;
cout << "What was your third score?" << endl;
cin >> score_third;
cout << "Your average score is: " << final_score << endl;
return 0;
}
Originally I am trying to get the average, by dividing the three scores, but that doesn't work, nor my arithmetic. It does not even multiple the variables. I use cin to get the numbers. Not sure what I am missing.
At the time that you assign to final_score, the values of the other scores are 0 (as you haven't assigned to them yet and they're global). You then read into the scores, but never update final_score!
You need to add this after you read in the third score:
final_score = score_one * score_two * score_third;
This will update final_score.
I would also suggest staying away from global variables. I'd also suggest initializing your variables when you declare them to avoid garbage values.
Also, you're not actually calculating the average! To do that, you'll need to add your values and divide by 3, since you have 3 values total. But you've declared final_score as an integer, so you won't be able to store the average with full precision. I'd suggest declaring as a double.
Taking into account all these changes, your code will look like:
int main()
{
int score_one = 0;
int score_two = 0;
int score_third = 0;
double final_score = 0;
cout << "What was your first score?" << endl;
cin >> score_one;
cout << "What was your second score?" << endl;
cin >> score_two;
cout << "What was your third score?" << endl;
cin >> score_third;
final_score = (score_one + score_two + score_third) / static_cast<double>(3);
cout << "Your average score is: " << final_score << endl;
return 0;
}
This line should be moved after you cin to the variables on the right hand side of the equation
int final_score = score_one * score_two * score_third;
cout << "Your average score is: " << final_score << endl;
The variable isn't somehow recomputed when those variables are later set.
This part
int final_score = score_one * score_two * score_third;
should be inside main() after the last cin.
You have already received some answers, but I would like to offer another point of view.
It seems to me that you are used to a program like Excel, where you can set a cell to a formula (like the product of 3 other cells), and then, whenever you change any of those cells, the product is immediately updated, automatically. C++ (and, in general, programming languages) does not work like that. When you write a line like
int final_score = score_one * score_two * score_third;
you are not setting a rule, which will cause the value to be recalculated. The approach is different!
A program is executed from the beginning to the end (in practice, from the top to the bottom), and every time you assign a value to a variable (like final_score), what you are doing is reading the current value of the input variables (here, your three scores), calculating the result (which in this case is undefined, because you haven't initialised any of the scores), and assigning it to the variable, just this time. That's it. If you later change the scores, the change will not be reflected automatically on your final_score. If you want the value to be recalculated, you have to do it manually. That's why you have to move that line after the lines that read the input from the user, as the others have said.
You really should not use global variables, see here on why you should avoid them.
Next, instead of doing using std::cin etc. Just get used to typing it.
Lastly, use appropriate flags in your compiler to help you catch mistakes. The compiler is meant to be your friend. A good compiler would tell you,
int score_one;
int score_two;
int score_third;
int final_score = score_one + score_two + score+third / 3;
Is not initialized. To really achieve what you are thinking, you could use a function that will return a double. And that would look something like
double doAverage(int score1, int score2, int score3)
{
return (score1 + score2 + score3) / 3.0;
}
But that will probably come later in your coding practices.
#include<iostream>
int main()
{
// Delare your variables here and initialize them to zero.
int score_one = 0;
int score_two = 0;
int score_third = 0;
double final_score = 0;
std::cout << "What was your first score?" << std::endl;
std::cin >> score_one;
std::cout << "What was your second score?" << std::endl;
std::cin >> score_two;
std::cout << "What was your third score?" << std::endl;
std::cin >> score_third;
// Take all scores and divide it. This is the important part since
// order matters in your code.
final_score = (score_one + score_two + score_third) / 3.0;
std::cout << "Your average score is: " << final_score << std::endl;
return 0;
}
You're on the right track, you just have to look at your code and read it outloud to yourself. One of the best things you can do in programming is starting from the top and saying, "Okay, where does this break?" And follow it line by line making sense of it.

Issue with calling function that takes in three parameters, one being int const [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
I'm posting because I'm having issues figuring out why my "total aid available" is not printing the total of the pell grant, stafford loan, and work-study loan. I've tried fixing my function again and again (I used sources online and in reference book, but I don't know if the issue is that my function won't be called or not, since nothing is printing for the total aid available.
Everything else is fine, except that one thing, and it is really bugging me since no matter what changes I make, I'm in the same state. No errors showing either. I'm using microsoft visual studio for the first time as compiler, so I wonder if that is the issue.
Here is what I have:
#include <iostream>
using namespace std;
double pell_Grant(double); // forward declaration on pell_Grant ( which is a function for calculating pell grant)
double sum(double, int const, double); // declaration for sum function which gives total for the total aid available
int main()
{
double workstudy = 0, pellgrant = 5730, grossincome = 0, Total = 0; // variables
int yes;
int const stafford = 9500; //const declaration
cout << "Lemme Forecast Your FAFSA" << endl;
cout << "Enter your adjusted gross income: " << endl; cin >> grossincome; // input for gross income
if (grossincome >= 30000) // if gross income is higher than 30,000 then print message
{
cout << "Sorry Charlie, your income is too high to run this forecaster!";
return 0;
}
cout << "Can someone claim you as a dependent? [1=yes/0=no]: " << endl; // input to claim dependent or not
cin >> yes;
if (yes == 1) // if 1 for yes is selected then pell grant gets reduced by 750, if 0 or no selected, then program goes by standard procedure
{
pellgrant -= 750;
}
workstudy = 1465; // work study must be nationwide avergae 1,465
if (grossincome >= 19000) // if this condition is met then work study is not met and message is printed as follows...
{
cout << "Your Work-Study Award is not available for your income level" << endl;
workstudy = 0;
}
double foo = pell_Grant(grossincome); // value returned from pell_Grant stored here to give total
Total = sum(workstudy + stafford + pellgrant); // sum function is called and stores result in Total
if (workstudy != 0) // if work study loan isn't more than 19,000 then it will be calculated and printed in next statement
{
cout << "Your Work-Study Award (if available)= " << workstudy << endl;
}
cout << "Your Stafford Loan award (if needed)= " << stafford << endl; // prints stafford loan (const called)
cout << "Your Pell Grant= " << pellgrant << endl; // prints pell grant
cout << "Total Aid Available For You=" << Total << endl; // prints total
return (0);
}
double pell_Grant(double x) // pell_Grant function that calculates pell grant which is assigned 5,730
{
// x is gross income which is assigned 5,730. This is money received that does not need to be repaid.
if ((x > 12000) && (x < 20000)) // statement makes sure adjusted gross is bettween 12000 & 20000
{
double a = x / 1000; // for every 1,000 in adjusted gross income... reduce/subtract 400 from it
a *= 400;
x -= a;
}
if (x > 20000) // check if gross income is more than 20000
{
double a = x / 1000; // for every 1,000 in gross income, subtract 500
a *= 500;
x -= a;
}
return x;
}
double sum(double workstudy , int const stafford, double pellgrant) // function for adding up workstudy loan, stafford loan, and pellgrant loan
{
double Total;
Total = workstudy + stafford + pellgrant;
return (Total); // returns total
}
According to its declaration, the method sum() accepts 3 parameters.
double sum(double, int const, double);
But while calling you are passing only 1 parameter:
Total = sum(workstudy + stafford + pellgrant);
Instead, you need to pass 3 parameters, like this:
Total = sum(workstudy, stafford, pellgrant);
But, I don't understand why you aren't getting any errors! You are trying to call a non-existent function. You must get a compiler error.
You are calling your sum() function incorrectly. This is your code:
Total = sum(workstudy + stafford + pellgrant); // sum function is called and stores result in Total
But your sum() function has three parameters. The correct form to call the function would be:
Total = sum(workstudy, stafford, pellgrant); // sum function is called and stores result in Total

How can I keep track of the coin number available coins in a vending machine? [closed]

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
I have a school project in c++ for a simple vending machine that accepts one-dollar-bills and give change in quarters, dimes, nickels. All the items cost less than 1 dollar .
But I need to add an extra ability to keep track of the available change in the machine, and I dont how to do it.
And this is the piece of code I wrote:
#include <iostream>
#include <string>
using namespace std;
int main()
{
//set the variables
int Qav=5 ;
int Dav=5 ;
int Nav=5 ;
int purchaseAmount ;
cout << "Simple Vending Program for Adam Ashouri (Regular Version)" <<endl;
cout <<endl;
cout <<endl;
cout << "Enter a purchase amount [5 - 100] -->";
cin >> purchaseAmount;
int chaneBack = 100 - purchaseAmount ;
changecalculator ();
}
void changecalculator ()
{
int purchaseAmount ;
int QBack ,DBack ,NBack ;
int chaneBack = 100 - purchaseAmount ;
if (purchaseAmount %5 == 0)
{
cout << "You entered a purchase amount of " << purchaseAmount << " cents." <<endl;
cout <<endl;
QBack = chaneBack / 25 ;
DBack = (chaneBack % 25) / 10;
NBack = (chaneBack %25 %10) / 5;
cout <<"Your change of " <<chaneBack <<" cents is given as " <<QBack <<" Q, " <<DBack <<" D,and " <<NBack <<" N." <<endl;
int coinsNum = QBack + DBack + NBack;
cout << "The value of your " <<coinsNum <<" coins adds up to " <<chaneBack <<" cents." <<endl;
cout << "Thank you for using my program.";
}
else
{
cout << "Unable to process an invalid purchase amout of " <<purchaseAmount <<" cents." <<endl;
cout << "Thank you for using my program." <<endl;
}
}
First of all, your current program doesn't work, because you don't transfer purchaseAmount inside function changecalculator(). You need to do it this way:
1) Change signature of the function to this: void changecalculator(int iPurchaseAmount)
2) Send purchaseAmount inside the function (i.e. call it this way: changecalculator(purchaseAmount);)
3) Use value iPurchaseAmount inside the body of your function and remove line int purchaseAmount; from it.
And about your main question (saving of number of available coins):
Ok, you've added Qav, Dav and Nav (available coins) in the body of your program. It is right. Now you have to transfer these values inside your changecalculator() function. Try to use this signature of your function: void changecalculator(int iPurchaseAmount, int& ioQav, int& ioDav, int& ioNav) (these values will be available inside body of the function). And call this function this way: changecalculator(purchaseAmount, Qav, Dav, Nav);.
After it you need only to analyze these values and change it inside the function. Let's add changeing of the values (it is necessary in case of many calls of this function). Just add following lines after calculation of QBack, DBack and NBack:
ioQav -= QBack;
ioDav -= DBack;
ioNav -= NBack;
And the most complex part of this task is analysis of values ioQav, ioDav, ioNav before calculation of QBack, DBack and NBack. Let's do it for quarters:
QBack = std::min(chaneBack / 25, ioQav);
It is calculation of the smallest value of two: available number of quarters and optimal number of quarters. So, this line calculates exactly what do you need. After it you can calculate number of dimes:
chaneBack -= QBack * 25; // subtract quarters
DBack = std::min(chaneBack / 10, ioDav);
If you understand this logic, you can complete it for NBack.

C++ Functions and Passing Variables [duplicate]

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
}