cout << "Please enter the current price per drywall sheet: "; cin >> getSheetPrice;
cout << "Please enter the height of the walls: "; cin >> getHeight;
cout << "Please enter the total length of the walls: "; cin >> getLength;
cout << "Please enter the number of outlets: "; cin >> getOutlets;
cout << setSheetsNeeded << " sheets of drywall are required." << endl;
cout << "Mudding and sanding will take " << setMudSandHours
<< " hour(s) and " << setMudSandMinutes << " minutes." << endl;
cout << "The total cost of the drywall (including tax 6%) will be $ " << setprecision(2) << showpoint << fixed << setDrywallCost << endl;
cout << "The total cost of labor will be $ " << setLaborCost << endl;
cout << "The total overall cost will be $ " << setprecision(2) << showpoint << fixed << setTotalCost << endl;
}
I am getting warnings C4700 that I use uninitialized local variables getHeight, getLength, getSheetPrice and getOutlets on lines 11,11,14 and 15 respectively. What's wrong with my code? Thanks.
-) You're using void main instead of int main. main should always return an int.
-) The warnings you're getting are exactly what they say. "Uninitialzed local variable" means you're using a variable before you initialize it.
Here:
1 2 3
float getHeight, getLength; // you declare variables here
int setSheetsNeeded = ((getHeight * getLength) / 32); // and use them in a computation here
But see... you never actually SET getHeight or getLength to anything. So what do you expect the result of that computation to be? How can the computer do math with these numbers if you never tell it what numbers you want?
Disch: Yes, you're correct. Initially my code was like below. I changed the order of the lines in order for the code to look "prettier" but it's not working. As for the int main part, it hasn't been taught to me yet. The program runs with void main () just fine.
#include <iostream>
#include <iomanip>
using namespace std;
void main()
{
float getSheetPrice;
cout << "Please enter the current price per drywall sheet: "; cin >> getSheetPrice;
float getHeight, getLength;
cout << "Please enter the height of the walls: "; cin >> getHeight;
cout << "Please enter the total length of the walls: "; cin >> getLength;
int getOutlets;
cout << "Please enter the number of outlets: "; cin >> getOutlets;
int setSheetsNeeded = ((getHeight * getLength) / 32) + 1;
cout << setSheetsNeeded << " sheets of drywall are required." << endl;
int setMudSandHours = (setSheetsNeeded * 45) / 60;
int setMudSandMinutes = (setSheetsNeeded * 45) % 60;
cout << "Mudding and sanding will take " << setMudSandHours << " hour(s) and " << setMudSandMinutes << " minutes." << endl;