I am currently in the process of doing a very simple homework programming in my first programming class, however I am stuck. I need to find the area of a house to find how much paint it needs. So I created a double variable (result) and initialized it using an equation to solve for the area, but my IDE reports that the local variable used in the equation are not initialized. However, I want these variables to be defined by the user not me. Hints and suggestions appreciated!
int main ()
{
double userentry, userentry1, userentry2, userentry3, userentry4;
double result = (userentry * userentry1) + ((userentry2 - userentry1) * userentry * 0.5);
cout << "Welcome to Paint Calculator 2014!" << endl;
cout << "\nHow wide is the wall (in feet)? ";
cin >> userentry;
cout << "and how high is the wall to the bottom of the roof? ";
cin >> userentry1;
cout << "and how high is the wall to the top of the roof? ";
cin >> userentry2;
cout << "How wide is the window (in feet)? ";
cin >> userentry3;
cout << "and what is the window's height? ";
cin >> userentry4;
cout << "\nA side wall that is " << endl;
cout << userentry << "'" << " wide and " << endl;
cout << userentry1 << "'" << " tall to the roof bottom and " << endl;
cout << userentry2 << "'" << " tall to the roof top, " << endl;
cout << "containing a window that is\t " << endl;
cout << userentry3 << "'" << "wide and " << endl;
cout << userentry4 << "'" << "tall, " << endl;
cout << "has "; cout << setprecision(1) << result;
return 0;
The program is executed in sequence. The user input is obtained after you have already tried to use it. That's like trying to cook a meal before you bought the ingredients.
Oh duh! I'm a dork. Thanks Chevril. I tried initializing it at line 27 before, but it returns the error "no operator '=' matches these operands". I've tried looking at examples of other users who encountered this error, but I'm too ignorant to understand their code at the moment. Does anyone know what that indicates?
should be moved to just after the cin statements, at line 18, or maybe at 26. (Either should do here).
Just a brief comment on variable names, it is better to use meaningful names such as height and width, rather than anonymous looking names userentry etc. which don't tell anything very useful.
Thanks again Chevril! You've been a great help! I put it in at 26 and it runs without a hitch and I'll definitely fix my coding style it needs some work.