Problem

Understanding Sequential StatementsIn this exercise, you use what you have learned about s...

Understanding Sequential Statements

In this exercise, you use what you have learned about sequential statements to read a scenario and then answer Questions. Suppose you have written a C++ program that calculates the amount of paint you need to cover the walls in your family room. Two walls are 9 feet high and 19.5 feet wide. The other two walls are 9 feet high and 20.0 feet wide. The salesperson at the home improvement store told you to buy 1 gallon of paint for every 150 square feet of wall you need to paint. Suppose you wrote the following code, but your program is not compiling. Take a few minutes to study this code, and then answer Questions.

// This program calculates the number of gallons of paint needed.#include using namespace std;int main(){double height1 = 9;double height2 = 9;int width1 = 19.5;double width2 = 20.0;double squareFeet;int numGallons;numGallons = squareFeet / 150;squareFeet = (width1 * height1 + width2 * height2) * 2;cout ≪ "Number of Gallons: " ≪ numGallons ≪ endl;return 0;}

When you compile this program, you receive a warning message from the cl compiler that is similar to the following:

c:\users\jo ann\c++ pal\chapter_2\student\paint.cpp(12) : warning C4700: uninitialized local variable 'squareFeet' used

There are multiple problems with this program even though the compiler issued only one warning message, which is pointing out an uninitialized variable on line number 12 in the source code file. You would know the compiler is complaining about line 12 because of the (12) in the warning message. On the following lines, describe how to fix all of the problems you can identify.

Step-by-Step Solution

Request Professional Solution

Request Solution!

We need at least 10 more requests to produce the solution.

0 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the solution will be notified once they are available.
Add your Solution
Textbook Solutions and Answers Search
Solutions For Problems in Chapter 2.5
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT